Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- r'That is Carol\s cat' #raw string. The slash are interprent as part of the string
- #Till the next triple quotes everything is interpreted
- #as string (backslashes, new line...). Nothing needs to be escaped
- """Dear...
- Today I've been....
- Regards,
- Fabio"""
- ##########################
- #strings: similar to list
- name[0]
- name[1:4}
- name[-1]
- 'fa' in name
- for i in name :
- print(name[i])
- ##but string are immutable in python!! They cannot be changed. To modify a string
- ##I need to create a new string
- name = 'Fabio'
- newName = name + ' Ciampi'
- ##########################
- count = {}
- pprint.pprint(count)
- pprint.pformat(count) #returns a string, instead of printing
- ####################
- spam = 'Hello'
- spam = spam.upper()
- spam.isupper()
- 'Hello'.isupper()
- isalpha()
- isdecimal()
- istitle()
- 'Ciao Fabio'.startswith('Fab')
- 'Ciao Fabio'.endswith('Fab')
- #concatenation
- spam = 'hello' + ' fabio'
- #join strings, using the provided separator
- ','.join('uno', 'due', 'tre')
- #split strings
- myList = 'My name is Fabio'.split()
- myList = 'My name is Fabio'.split('m')
- #padding
- 'Hello'.rjust(10) #pad the string to make it lenght 10
- 'Hello'.ljust(10) #pad the string to make it lenght 10
- 'Hello'.rjust(10, '*') #define the padding character
- 'Hello'.center(10)
- #stripping
- spam.strip() #returns a string without spaces
- spam.lstrip()
- spam.rstrip('=') #remove from the right one specific char
- #replace
- spam = 'Hello world'
- spam.replace('e', 'bla')
- #copy/paste to clipboard
- import pyperclip
- pyperclip.copy("Hello") #writes to the clipboard
- pyperclip.paste() #get the content of the clipboard
- #string formatting
- name = 'fabio'
- local = 'johnny'
- 'Hello %s, do you come at %s?' % (name, local)
Add Comment
Please, Sign In to add comment