Back to marketplace

strings, files and arrays

No description yet. This curated deck is ready for daily study.

Total cards: 24•Content version: v4•Public deck•Updated: 8/1/2026

Card preview (24)

#1
Front (Question)

mystring = “Hello” how can i save the length of the string in the variable x

Back (Answer)

x = len(mystring)

#2
Front (Question)

methods

Back (Answer)

-methods work similarly to functions. - they are written like this mystring.upper() and return a value

#3
Front (Question)

mystring = “Hello” what methods will return 1) “HELLO” 2) “hello”

Back (Answer)

1) mystring.upper() 2) mystring.lower()

#4
Front (Question)

mystring = “Hello” what method will count the number of times “e” occurs in the string

Back (Answer)

mystring.count(“e”)

#5
Front (Question)

mystring = “Hello” what method will replace all instances of “e” with “x” in the string. (output “Hxllo”)

Back (Answer)

mystring.replace(“e”, “x”)

#6
Front (Question)

mystring = “Hello” how can i retreive the first letter of the string

Back (Answer)

mystring[0]

#7
Front (Question)

mystring = “Hello” write a loop which prints each letter of this string seperately.

Back (Answer)

for i in range (len(mystring)): print(mystring[i])

#8
Front (Question)

mystring = “Hello” how can i take a “slice” of this string, leaving only the letters “ell”

Back (Answer)

mystring[1:3]

#9
Front (Question)

mystring = “Hello” how can i take a “slice” of this string, leaving out the first two letters

Back (Answer)

mystring[2:]

#10
Front (Question)

mystring = “Hello” how can i take a “slice” of this string, leaving out the last two letters

Back (Answer)

mystring[:3]

#11
Front (Question)

what does slicing look like in psuedocode

Back (Answer)

mystring, substring(1,4)

#12
Front (Question)

how to reference a file name in your program.

Back (Answer)

save the name as a string constant. eg. FILENAME = “highscore.txt” then it can be used as myfile

#13
Front (Question)

given FILENAME = “highscore.txt” savetext= “200” write some code to save 200 to the text document.

Back (Answer)

with open( FILENAME, “a”) as myfile: myfile.write(savetext)

#14
Front (Question)

given FILENAME = “highscore.txt” write some code to save the contents of the document to a variable x

Back (Answer)

with open (FILENAME, “r”) as myfile: x= myfile.read()

#15
Front (Question)

what are the conditions for reading a text file into a variable

Back (Answer)

• file must be text only • must be in your python directory

#16
Front (Question)

write a list called mylist , that holds the strings “a” “b” “c”

Back (Answer)

mylist = [“a” , “b”, “c”]

#17
Front (Question)

what are items in a list called

Back (Answer)

elements they can be different data types

#18
Front (Question)

make an empty list called mylist. Then append “a” to the list.

Back (Answer)

mylist = [] mylist.append(“a”)

#19
Front (Question)

given mylist =[ “a”, “b”, “c”] write one line of code to print “b” from the list

Back (Answer)

print(mylist[1])

#20
Front (Question)

given mylist =[ “a”, “b”, “c”] write one line of code to ovverwrite the element “b” with “x”

Back (Answer)

mylist[1] = “x”

#21
Front (Question)

mylist =[ “a”, “b”, “c”] delete the element “b” using it’s element number

Back (Answer)

del mylist[1]

#22
Front (Question)

mylist =[ “a”, “b”, “c”] remove the element “b” using it’s content

Back (Answer)

mylist.remove(“b”)

#23
Front (Question)

write a boolean expression that checks if the string “a” is in the list called mylist

Back (Answer)

“a” in mylist

#24
Front (Question)

write an if structure that prints “correct” if the string “b” is found in the list mylist

Back (Answer)

if “b” in mylist: print(“correct”)