Ch. 5 Flashcards
strings, lists, files (34 cards)
accessing a single character out of a string is called
indexing
which of the following is same as [0:-1]
s[:len(s)-1 ]
what function gives the unicode value of a character?
ord
which of the following can not be used to convert a string of digits into a number
eval
a successor to ASCII that includes characters from (nearly) all written languages is
unicode
Which string method converts all the characters of a string to upper case?
upper
The string “slots” that are filled in by the format method are marked by:
{}
which of the following is not a file-reading method in python
readall
the term for a program that does its input and output with files is
batch
Before reading or writing to a file, a file object must be created via:
open
s1 = “spam”
s2 = “ni!”
“The Knights who say, “ + s2
the knights who say ni!
s1 = “spam”
s2 = “ni!”
3 * s1 + 2 * s2
spamspamspamni!ni!
s1 = “spam”
s2 = “ni!”
s1[1]
p
s1 = “spam”
s2 = “ni!”
s1[1:3]
pa
s1 = “spam”
s2 = “ni!”
s1[2] + s2[:2]
ani
s1 = “spam”
s2 = “ni!”
s1 + s2[-1]
spam!
s1 = “spam”
s2 = “ni!”
s1.upper()
SPAM
s1 = “spam”
s2 = “ni!”
s2.upper().ljust(4) * 3
NI! NI! NI!
s1 = “spam”
s2 = “ni!”
spam
s1
s1 = “spam”
s2 = “ni!”
NI!
s2[0:2].upper()
s1 = “spam”
s2 = “ni!”
ni!spamni!
s2 + s1 + s2
s1 = “spam”
s2 = “ni!”
spm
s1[0:2] + s1[-1]
“Looks like (1) and (0) for breakfast”.format(“eggs”, “spam”)
not legal bc curly braces are required around 1 and 0
“There is {0} {1} {2} {3}”.format(1, “spam”, 4 “you”)
‘There is 1 spam 4 you.’