Strings Flashcards
1
Q
REPRESENTATION
Strings are represented as lists or tuples ??
A
Strings are represented as tuples of characters, which means they are inmutable objects.
2
Q
CONCATENATION
a = "foo" b = "bar"
How do you concatenate strings a and b?
A
c = a + b
c = “foobar”
3
Q
MEMBERSHIP
a = "foo" sentence = "I lo ve food"
How can you check if string a is part of sentence?
A
# The statement returns a boolean a in sentence
4
Q
my_name = “Georcge Michael The Second”
How can you know how many characters are there in my_name?
A
#Use the built in function len() num_char = len(my_name)
5
Q
my_string = “This is a sort of long string”
Get a list containing the different words in my_strind
A
#Use the built in function str.split() my_string.split()
6
Q
my_string = “animales domesticos; animales de granja; animales salvajes”
Get a list containing the different kind of animals named in my_string
A
#Use the built in function str.split() my_string.split("; ")