name = "Evry"
print(name[0], name[2])E r
Link to the Google Colaboratory notebook: 4-Strings
Strings in python are surrounded by either single quotation marks, or double quotation marks.
'hello' is the same as "hello".
Strings in Python are arrays of bytes representing unicode characters.
A single character is simply a string with a length of 1.
You can access elements of a string using square brackets:
You can get the length of a string using the len function.
You can check if a string is inside another one.
To do so, you can use the in syntax:
In Python, we can return a range of characters using the slice syntax.
Specify the start and the end index, separated by a colon:
Python has built-in methods to modify strings.
You can convert to uppercase or lowercase a string with the functions .upper() or .lower():
You can remove whitespace from a string that is located at the beginning or the end.
Use the .strip() function:
Sometimes it can be usefull to replace a string by another value.
The .replace function does it:
The split() method returns a list where the text between the specified separator becomes the list items.