Back to marketplace

Py Lists (Datacamp + UCSD Wk 2)

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)

Assign a value to a variable

Back (Answer)

eg, x = 5

#2
Front (Question)

print values

Back (Answer)

print()

#3
Front (Question)

Exponents in python

Back (Answer)

base ** exp

#4
Front (Question)

find out the type of a variable

Back (Answer)

type(variable)

#5
Front (Question)

concatenate strings

Back (Answer)

str3 = str1 + str2

#6
Front (Question)

convert a string to a float

Back (Answer)

pi_float = float(“3.14”)

#7
Front (Question)

convert int or float to string

Back (Answer)

str(int_var) or string(numerical value)

#8
Front (Question)

can you multiply a string by a number?

Back (Answer)

Yes. “hey” * 2 = “heyhey”

#9
Front (Question)

what are lists?

Back (Answer)

lists are arrays, and can have have various data types, including other lists

#10
Front (Question)

how to assign values to a list

Back (Answer)

list = [var1, var2, 5, “hello”]

#11
Front (Question)

how do you create a 2 dim array with lists

Back (Answer)

2d = [[“val1”, var1] , [“val2”, var2]]

#12
Front (Question)

How do you retrieve individual elements of a list (subset)

Back (Answer)

list[0] (first element]; list[-1] (last element)

#13
Front (Question)

How do you retrieve multiple elements from a list (slice)

Back (Answer)

list[1:3] - returns elements 1 and 2 (inc start, exc end)

#14
Front (Question)

Do you have to specify begin and end of the indices for your list slice?

Back (Answer)

no. if blank, python will go to end. eg, list[ : 5] will do from begin to 5.

#15
Front (Question)

specify elements from n-dim list (eg, 2 dim)

Back (Answer)

list [1] [2], or list [2] [0:2] - elements 0 to 2 from list 2

#16
Front (Question)

how to replace list elements?

Back (Answer)

x[2:3] = [”s”, “t”]

#17
Front (Question)

how to extend a list

Back (Answer)

list2 = list1 + [“e”, “f”]

#18
Front (Question)

remove an element from a list

Back (Answer)

del( list [1] )»_space; removes element 1, and renumbers all indexed elements after

#19
Front (Question)

Point a new list at another list

Back (Answer)

newList = oldList (points to the same array)

#20
Front (Question)

copy the values of a list into a new list (eg, new ind. data structure)

Back (Answer)

copiedList = oldList[ : ]

#21
Front (Question)

append 4 to list [1,2,3] (appends an element to the end. )

Back (Answer)

list.append(4)

#22
Front (Question)

iterate over values in a list

Back (Answer)

for i in list: print(i)

#23
Front (Question)

iterate over list using range

Back (Answer)

for i in range(0, len(list)): print(list[i])

#24
Front (Question)

lists are mutable

Back (Answer)

you can change the values in the list