Python Data Types Flashcards

1
Q

Numeric Types

A

Int, Float, Complex

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

Int

A

Ints are considered a primitive scalar type

Ints allow for unlimited precision (as many digits as you need)

Integers are always rounded towards zero
int(3.9) = 3
int(-3.9)=-3

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

float

A

float = floating point number

any number containing a decimal is interpreted as a float in python

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

None

A

None = null object (represents the absence of a value)

We can assign a value as None using the assignment operator: a = None

We can test if something is None using the “is” operator
a is none // True

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

bool

A

bool = boolean objects (True / False)

represents logical states and play an important role in Python control flow structures

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

str

A

str = string
this is a collection type
strings are sequences of chars
strings are IMMUTABLE meaning once you have constructed a string, you cannot modify its contents

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

tuple

A

a tuple is a collection

a tuple is:
- ordered
- immutable (we cannot add or remove items)
- allow duplicates

similar syntax to lists, but they use parentheses

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

set

A

A set is a collection

sets are
- unordered
- unindexed
- mutable
- no duplicates

items within a set are unchangeable, but you can remove items and add new ones

A common use for a set is to remove duplicate items from a series of objects

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

list

A

A list is a collection

Lists are:
- ordered
- mutable
- allow duplicate values
- indexed

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

range

A

range = a sequence representing an arithmetic progression of integers, generated by calls to the range constructor

range determines what it’s arguments mean by counting them

one arg = range(stop)
two arg = range(start, stop)
three args = range(start, stop, step)

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

dict

A

dicts are iterable and their keys are immutable, but their values are mutable
dicts contain key/value pairs with unique keys
key objects must be immutable (strings, numbers, tuples)
you cannot rely on the order of items in a dict

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