upper() return string
lower()
isupper(), isalpha(),isalnum(),isspace(),isdecimal() return bool
islower(),istitle()
spam = 'hello world'
print spam.upper()
startwith() . return bool
endswith()
'hello world'.startwith('hello')
True
join() . return a string combine with a list of strings
','.join('cat','rats','dogs')
>>>'cat,rats,dogs'
split() . return a list of strings
rjust(),ljust() return a string padded with space
'hello'.rjust(10)
>>>' hello'
len(' hello')
>>>10
'hello'.rjust(20,'*')
>>>'***************hello'
center()
strip(),lstrip(),rstrip() . return a string with whitespace stripped off the sides
' hello'.strip()
>>>'hello'
'SpamSpamBaconSpamEggsSpamSpam'.strip('ampS')
>>>'BaconSpamEggs'
replace(),
replace() doesn't modify the original string, but returns a copy. So you need the assignment for the code to have any effect.
>>> string="abc&def#ghi"
>>> for ch in ['&','#']:
... if ch in string:
... string=string.replace(ch,"\\"+ch)
spam = 'hello there'
spam.replace('e','xyz')
>>>'hxyzllo thxyzrxyz')
#will replace all the item
pyperclip
use pip to install
import pyperclip
has copy() and paste() function for using the clipboard
index()
find()
uname = 'Linux #1 SMP Tue Feb 12 02:46:46 UTC 2008'
1:
'Linux' in uname
>> True
2:
uname.find('Linux')
>> 0(yes) or -1(no)
uname.index('Linux')
>> number or error exception