Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #---!PRETTY MUCH ALL ABOUT STRINGS!---PYTHON VERSION: 3.3.3 IDLE VERSION: 3.3.3
- string1 = "hello world!"
- string2 = " hello world!" #Meant for strip() function
- print(string1[0:4])
- #Retrieve the first four characters of the string.
- print(string1[2:5])
- #Retrieve the characters between index 2 to index 5 in the string.
- print(string1[:-5])
- #Retrieve the last 5 characters of the string.
- print("%s" % (string1))
- #String Formatting (You can also do %c for character and %d for integer.)
- print(string1.capitalize())
- #Will capitalize the first character in a string.
- print(string1.find("world"))
- '''
- Will find the word world and output the index number of the word's first
- character.
- '''
- print(string1.isalpha())
- #Returns true if all characters are letters in the string.
- print(string1.isalnum())
- #Returns true if all characters are numbers.
- print(len(string1))
- #Returns the length of the string.
- print(string1[:4] + " noooo")
- #Prints out the first four letters of the string and then adds the the word noo.
- print(string1.replace("hello", "hey"))
- #Replaces the word hello with hey.
- print(string2.strip())
- #Remove white space from front and end.
- list1 = string1.split(" ")
- print(list1)
- #Split a string into a list based on the delimiter you provide.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement