Lecture 4 - More on strings Flashcards

1
Q

what is the similarity and difference between str and repr

A

Similarity: both functions convert other types to string

Difference: while repr gives back the exact underlying string value (useful for programmers while debugging) str gives back readable string values which sometimes leads to the manipulation (like shortening) of the exact values.

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

String Interpolation is equivalent to

A

Formatting other types to string

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

%s, %d, %o, %x, %f, %%

A

string, integer, octal number, hexadecimal values, float point, to print

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

Python uses __ ordering for comparing strings

Define it.

A

lexicographic ordering - compares the first to the first, if they differ it determines the outcome; if they are equal it compares the next two values and so on until either is exhausted

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

‘FRED’

A

“fred”.upper( )

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

‘fred’

A

“FRED”.lower( )

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

2

A

“Mississippi”.count(“ss”)

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

“iss” in “Mississippi”

A

True

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

Given a positive integer, calculate the number of digits

it has in base 10

A

i = 10

len.(“%d” % i)

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