Strings
Can be enclosed in single or double quotes
a ='some text'
b = "some text"
print(type(a)) '<class 'str'>
Multi-Line
We can use three single quotes
myText = '''Some
Multi Line
Text'''
print(myText)
String Concatenation
Use the plus operator
str1 = "some"
str2 = "text"
result = str1 + str2
print(result[3]) ' positive indices from the left / start
print(result[-3]) ' negative indices from the right / end
str3 = '' ' empty string
Slicing
str = 'some text'
print(str[0:4])
The first character position is 0 and the length is 4
str = 'some text'
print(len(str))
SubString Exists
str = "better solutions"
print(str.split(' ')
print('better' in str)
Strings slicing
person_name = "Grace Hopper"
print(person_name[0]) #= "G" first character
print(person_name[1]) #= "r" second character
print(person_name[2]) #= "a" third character
Strings negative indices
word = "hamster"
print(word[-1]) #= r
print(word[1:-1]) #= amste
print(word[-3:]) #= ter
print(word[:3]) #= ham
line continuation - triple quoted strings
my_variable = """This is a long multi-line
text block. Notice how it can spill onto
multiple lines. It has been assigned to a new
variable called my_variable. You can use 'single'
and "double" quotes inside."""
print(my_variable)
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopNext