w2 Flashcards

(57 cards)

1
Q

what does \n mean

A

represents a new line

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

print(item1 * 5)

A

prints the item1 5 times

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

how do I combine strings

A

items = item1 + “\n” + item 2

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

words1 = item1.split()

A

separates the words on the string item1

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

words1 = item1.split(“a”)

A

split the string at every occurrence of a, removing a

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

is “item 1 = playstation” valid??

A

no nigga no spaces in variable names

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

What are lists

A

used for keeping track of a sequence of items

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

what does len() do

A

determines how many items (elements) are in a list

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

how to determine a specific item in list

A

my_comp[2]

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

how to determine last item in a list

A

my_comp[-1]

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

adding item to a list

A

listname.append(‘item_name’)

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

adding item to specific point/number

A

listname.append(specific index, ‘item_name’)

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

removing items

A

listname.remove(‘item_name’)

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

removing item to specific point/number

A

listname.pop(‘specific index’)

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

what happens if no index is given for removing items

A

will remove last item

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

explain negative indexing

A

refers from starting from the end, -1 refers to last item, -2 refers to second last item etc

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

what is index of first item

A

0

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

slicing code

A

list name[startindex:endindex]

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

detail about end index

A

it is always excluded

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

what happens when you leave out the start index from slicing i.e [:2]

A

will start from the first item

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

what happens when you leave out the end index from slicing i.e [2:]

A

will finish at the last item

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

changing a range of items?

A

list_name[start:end] = “values to update”

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

What is a tuple

A

An ordered sequence of elements that is unchangeable (immutable)

24
Q

what is a set

A

A disorganised collection of unique elements

25
Dictionary
An ordered collection of unique elements
26
Are lists mutable
yes
27
Are tuples mutable
no
28
Are sets mutable
yes the entire set is but items inside the set is immutable i.e integers, strings
29
are dictionaries mutable
yes
30
are lists ordered
yes
31
are tuples ordered
yes
32
are sets ordered
no
33
are dictionaries ordered
yes
34
are lists able to be indexed/sliced
yes
35
are tuples able to be indexed/sliced
yes
36
are sets able to be indexed/sliced
no
37
are dictionaries able to be indexed/sliced
yes
38
do lists allow duplicate elements
yes
39
do tuples allow duplicate elements
yes
40
do sets allow duplicate elements
no
41
do dictionaries allow duplicate elements
no
42
what does [] rep
lists
43
what does () rep
tuples
44
what does {} rep
sets, dictionaries
45
diff between sets and dictionaries
Sets contain only values (no key-value pairs). Dictionaries contain key-value pairs, where each key is associated with a value.
46
why can't tuples be updated easily
they are immutable
47
how to update tuples process
convert tuple into a list do append or remove convert it back to a tuple
48
explain range () function
range(start number, end number (not included), increment number)
49
what would range (2, 12, 3) print
2,5,8,11
50
what is a literal
just a constant
51
what are string literals
text inclosed by delimeters
52
what are delimiters and examples
characters seperating data examples are single or double quotation marks
53
when should triple delimiters be used
when string includes characters on a new line
54
how do you make a prompt and return the answer as a string say like for a name
name = input("what's ur name?")
55
how do you make a prompt and return the answer as an integer say for weight
weight = int(input("how much do you weigh"))
56
explain formatting with f string
f"{variable:{width}.{precision}f}" width refers to how far across precision refers to how many d.p f is a fixed point
57