Strings Flashcards
Write a brief description of strings in Python.
Strings are used to record text information. They can be used with double or single quotations and are immutable
Write a one word string
‘hello’
Write a phase in a string
"”hello world this is a string”
‘I’m using single quotes but I will still get an error’
Explain why an error will occur.
An error will ouccur because there is a single quote in What’s stopped the string. Using single and quote combinations will get the complete statement.
“I’m now able use single quotes inside a string”
How do you output multiple strings?
Use a print statement to print a string.
print(‘hello world’)
print(hello world 2’)
What function is used to check the length of a string
len()
s = ‘Hello World’
What element is:
s[0]
‘H’
s = ‘Hello World’
What element is:
s[4]
‘o’
s = ‘Hello World’
output - s[1:]
s[1:] ‘ ello World’
s = ‘Hello World’
output s[:3]
‘Hel’
s = ‘Hello World’
Grab everything
s[:]
s = ‘Hello World’
output [:-1]
‘d’
s = ‘Hello World’
Grab everything in steps size 2
s[::2] ‘HloWrd’
s = ‘Hello World’
output - s[::-1]
‘dlroW olleH’
Strings are Immutable True or False?
True