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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

CONCATENATION

a = "foo"
b = "bar"

How do you concatenate strings a and b?

A

c = a + b

c = “foobar”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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("; ")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly