Lecture 4 - More on strings Flashcards
what is the similarity and difference between str and repr
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.
String Interpolation is equivalent to
Formatting other types to string
%s, %d, %o, %x, %f, %%
string, integer, octal number, hexadecimal values, float point, to print
Python uses __ ordering for comparing strings
Define it.
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
‘FRED’
“fred”.upper( )
‘fred’
“FRED”.lower( )
2
“Mississippi”.count(“ss”)
“iss” in “Mississippi”
True
Given a positive integer, calculate the number of digits
it has in base 10
i = 10
len.(“%d” % i)