Data Types Flashcards

1
Q

Literal

A

notation for representing a fixed value of a specific data type

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

Iterable

A

object that can be iterated over in a for loop

object that you can pass to the iter function to get an iterator from it

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

Iterator Protocol

A

__iter__()
__next__()

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

Sequence

A

Ordered collection of elements.
Any sequence is iterable

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

Mutable and immutable sequences

A

Mutable: list, bytearray

Immutable
tuple, range, string, bytes
support hash() therefore can be used as dict keys and stored in set

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

Sequence operations

A
  • indexing
  • slicing
  • membership (in, not in)
  • concatenation (+) (except range)
  • repetition (*) (except range)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Sequence methods

A

Common
index(index)
count()

Mutable
append(value)
extend(value)
insert(value, index)
pop(index)
remove(value)
reverse()
clear()
copy()

List
sort()

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

Iterator

A

object that implements the iterator protocol

iterators are iterables
single-use

next(iterator[, default])

calling next on exhausted iterator raises StopIteration

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

List

A

list()

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

Tuple

A

()
tuple()

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

Bytes

A

bytes()

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

Generator function

A

returns generator object
yield instead of return

PEP 255

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

Numeric Types

A

int
float
complex

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

Generator

A

Generator function returns generator object - type of iterator
generator expression
yield from
return smth == StopIteration(smth)

PEP 380

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

Type Hints

A
def func(arg1: type1, arg2: type2 = default, ...) -> return_type:
    ...

o.__annotations__

inspect.get_annotations(obj, *, globals=None, locals=None, eval_str=False)

from typing import Any

mypy, pyright, typeguard

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

Float

A

scientific notation NeM

any operation involving a float returns a float

17
Q

Set

A

class set([iterable])
class frozenset([iterable])

unordered collection of distinct hashable objects

18
Q

Sequence functions

A

len(s)
min(s)
max(s)