Defining Strings
Use either “ “ or ‘ ‘. Don’t use them together otherwise you’ll get an error message! You can assign Strings a variable like an int or a double. They can be assigned to a variable, as seen below.
Printing
Use the print() method. You can directly print strings or print from a variable. You can also concatenate strings within the method. ex: print(string1 + string2)
Concatenating
Use the + symbol between String. If you want to add a space between the strings, don’t forget to add a “ “.
Strings → Ints and Ints → Strings
When you want to combine an int and a string, write str(variable) to convert the int to a string.
Indexing
This allows you take a specific character or set of characters from a string.
Remember that the index starts with 0, not 1! The first character would have the index of 0, not 1.
To get a letter at a specific index, you write string[index].
To get a specific segment of a string, you use the following function: write string[a:b]
a is the index that the substring will start from. b-1 is the index that the substring will end on. if you write no values for a and b: string[:], you will get the entire string.
Remember that the index starts with 0, not 1! The first character would have the index of 0, not 1.
To get a letter at a specific index, you write string[index].
To get a specific segment of a string, you use the following function: write string[a:b]
a is the index that the substring will start from. b-1 is the index that the substring will end on. if you write no values for a and b: string[:], you will get the entire string.
len() is used to find the length of a string.