Strings Flashcards

1
Q

True or False: You have to use double quotes for strings in Python

A

False - you can use single or double quotes

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

How would you slice a string to get only certain letters in a string?

A

s = ‘abc’
s[0:2]

result = ‘ab’

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

True or False: strings are immutable in Python and cannot be reassigned like lists

A

True - any string modification will result in the creation of a new string, thus O(n) time

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

How can you add a letter to the end of a string in Python?

A

s = ‘abc’

s += ‘d’

This will result in a new string of O(n) time complexity

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

How would you add the values ‘123’ and ‘456’?

A

n = int(‘123’)
m = int(‘456’)

result = n + m

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

How would you create a string from 123 and 456

A

n = str(123)
m = str(456)

newString = n + m

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

What is the built-in function to get the ASCII value of a character in Python?

A

ord(“a”)

Result is 97

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

How can we combine strings using a delimiter in Python?

A

”“.join(strings)

This is a delimiter because it creates a new string with all other values included

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