Unit 9 : String Flashcards
What is string?
- A sequence of characters
What uses to configure strings values? ( 2 )
- ’’
- ””
What does + means in python?
- Concatenate
What are the type for number in strings?
- String
How can we convert numbers in string into integer?
- Using int()
How can we get single character from a string variable?
- Using an index specified in square brackets
What are the rules for index value? ( 2 )
- The index value must be an integer and starts at zero
- The index value can be an expression that is computed
What will we get when we attempt to inde beyond the end of a sting
- Get a python error
How can we loop through string?
fruit = “banana”
index = 0
while index < len(fruit):
letter = fruit[index]
print(index, letter)
index = index + 1
for letter in fruit:
print(letter)
while index < len(fruit):
letter = fruit[index]
print(letter)
index += 1
How can we get the length of a string?
- len() function
fruit = “banana”
print(len(fruit)) # 6