Strings Flashcards
What programs use string to perform operations?
search engines, emails
How to iterate over a string= “AMANDA”
for count in string:
print count
How can you access individual characters with a string?
via index
Indexing starts at ?
0
provide an example of index
name = “Sakura”
name[2]
k
Negative numbers in index starts with?
example
-1
for instance: name =”Sakura”
name[-1] = “a”
name[-2] =”r”
what error does this give?
name =”AVA”
name[4]
IndexError Exception
How do you find the length of a string?
name = “Sakura”
len(name)
How do you concatinate two or more strings?
use the + operator
You can also use what to concatinate? Demonstrate
\+= a ="av" a+="a" print (a) ava
Strings are mutable or immutable. Why?
Immutable. Cannot be changed. a= "a" a += "va" in the memory its a ava
Can you do this? Why? Why not?
name =”ava”
name[0] =”f”
No cause strings are immutable.
What is slicing used for?
to select a range of characters from a string
String slices are also called
substrings
Syntax for slicing
string [start:end]