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)
- allows 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 a mapping type

store values as key-value pairs

  • iterable
  • keys are immutable, unique (strings, numbers, tuples)
  • values are mutable

as of Python 3.7, dicts are ordered

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

Primitive

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

Non-Primitive

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

Immutable

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

Sequence

A

Type of Collection (there are three: sequence, set, mapping)

Ordered
It’s elements can be accessed using a numeric index

examples: lists, tuples, ranges

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

Mapping

A

Type of Collection (there are three: sequence, set, mapping)

stores data in key-value pairs

ordered

example: dict

17
Q

Set

A

{ }

Type of Collection (there are three: sequence, set, mapping)

  • Unordered
  • Immutable
  • comprised of unique objects
18
Q

Collection

A

A collection is an object that has zero or more member objects, called elements

Categories of collections:
1. sequences (list, tuple, range)
2. mappings (dict)
3. sets (set, frozenset)

19
Q

Text Sequence

A

Strings and other text sequences are not considered collections

however, they are very similar to sequence collections

example: str

20
Q

Literal

A

A literal is a syntactic notation that lets you directly represent an object in source code

they are constants that are directly written into the code and don’t need to be computed or evaluated

You can use literals to represent most data type values

21
Q

Numeric

A

Numeric values represent numbers

integers and floats are both numeric values