Chapter 3 (strings) Flashcards

1
Q

What are the types of sequences?

A
  • String
  • List
  • Tuple
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the properties of a string?

A
  • Immutable, must be assigned a new string
  • Only stores single characters in a sequence
  • Can be iterated by element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the properties of a list?

A
  • Mutable
  • Can hold any data type
  • Can hold more than one character per index
  • Can be iterated by element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the properties of a tuple?

A
  • Immutable
  • Can hold any data type
  • Can hold more than one character per index
  • Can be iterated by element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the notation for finding the element of a sequence type by index?

A

sequence[index]

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

What is the only mapping type in Python?

A

Dictionary

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

What makes a mapping type different from a sequence type?

A

Both act as containers that hold values, but the mapping types are not ordered, their contents cannot be searched using an index number
- A dictionary uses a key-value pairs instead of index-value pairs

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

What is a set?

A

A separate type from mapping or sequence types, simply an unordered list of unique elements

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

How do you declare an empty and prefilled list?

A

Empty) list = []
Prefilled) list = [1,2,3,4,5]

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

How do you declare an empty and prefilled tuple?

A

empty) tuple = ()
prefilled) tuple = (1,2,3,4)

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

How do you declare an empty and prefilled dictionary?

A

Empty) dict = {}
Prefilled) dict = {‘joe’: 18, ‘Dan’: 19}
dict = {key:value}

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

How do you limit the number of decimal places in an output?

A

~ let x be the number of values after the decimal point

print(f’{value:.xf}’)

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

How do you find the length of a sequence?

A

len()

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

How do you find the final value in a sequence?

A

sequence[-1]
- indexing works as a circle, so you [0] is the first and [-1] is the last, you can keep going back the sequence as long as you don’t exceed the first value of the sequence
- e.g. name =’danial’ name[-12] would create an error

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

what is the function of \?

A

Ignore the following character in a print statement

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

What is the format for deleting index in a lists

A

Del list[index]

17
Q

What is the Pop() function format

A

List.pop(index)
List.pop() auto does last

18
Q

How do you declare an empty and prefilled tuple?

A

empty) tuple = ()
prefilled) (1,2,3,4)