name = 'Benedict Cumberbatch'
name.upper()
name
It doesn't change the actual value.
To change the string value stored in a variable, we do the following
name = name.upper()
name
name.lower()
isupper or islower
name.isupper()
somestr = 'ThIs iS A StRiNg'
somestr.isupper()
somestr.islower()
nothing = ''
nothing.isupper()
nothing.islower()
'12345'.isupper()
'something here'.islower()
'elon Musk'.upper()
'elon Musk'.upper().isupper()
'hello'.isalpha()
'hello123'.isalpha()
'123'.isdecimal()
' '.isspace()
'This Is A Example Of Title Case'.istitle() #All words begin with uppercase
'i am gonna make this title case'.title()
'Elon Musk'[4].isspace()
'Iron Man'.startswith('Iron')
'Iron Man'.startswith('')
'Tony Stark!'.endswith('Stark!')
'Tomy Stark!'.endswith('Stark')
','.join(['some','things','here'])
'00000000'.join(['some','things','here'])
'\n\n'.join(['some','things','here'])
print('\n\n'.join(['some','things','here']))
''.join(['some','things','here'])
'This is captain Kirk speaking'.split()
'This is captain Kirk speaking'.split('i')
'55055502202'.split('0')
How to add these numbers
addlist = '55055502202'.split('0')
total = 0
for i in addlist:
total = total + int(i)
print(total)
'Hello'.rjust(10)
What it does:
len('Hello'.rjust(10))
'Hello'.rjust(4)
'Hello'.ljust(20)
Optional second argument can be specified to specify what should be used to fill.
'Emma'.ljust(20,'*')
'Hello'.center(20,'*')
len('*******') #length of the asterisks added in the left side
len('********') #Length of the asterisks added in the right side
len('Hello'.center(20,'*'))
somestr = ' hello '
somestr.strip()
somestr #Doesn't change the original string variable
somestr.lstrip()
somestr.rstrip()
We can specify to remove any character(s) we want.
somestr = 'SpamSpamBaconEggsSpamEggsSpamSpam'
order of characters in the argument of strip doesnt't matter. It's going to remove all of them. In the following case - S,p,a,m from the ends
somestr.strip('maSp')
Notice the Spam in the inside isn't removed.
i.e when it encounters some character it isn't supposed to remove, it stops.
spam = 'street'
spam.replace('e', 'XYZ')
spam
spam = spam.replace('e', 'XYZ')
spam
copy and paste functions from pyperclip module are used to copy to the clipboard or paste from clipboard respectively.
import pyperclip
copy('hello')
I will leave that error for future reference
import pyperclip
pyperclip.copy('hello!!!!!!')
pyperclip.paste()
something = pyperclip.paste()
something