Python Terms Flashcards

1
Q

Int

A

Number without any decimal precision

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

Float

A

Number with decimal precision

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

Boolean

A

1 or 0. True or False

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

Str

A

String. Text enclosed in quotes. Either ‘ or “

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

Tuple

A
  • Used to store multiple items in a single variable
  • Mytupe = (‘apple’, ‘banana’, ‘cherry’)
  • A tuple is a collection which is ordered and unchangeable
  • Ex: coord1 = (-35, 50). We cannot do: coord1[0] = -36. We can’t change the value in position 1 of the tuple. We can only save over the like coord1 = (-36, 50)
  • Unchangeable object means it is immutable object.
  • Tuples are smaller in memory compared to other objects like list, set, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

List

A
  • Used to store multiple items in a single variable.
  • Lists are ordered, changeable (mutable), and allow duplicate values.
  • List items are indexed, the first item has index [0], the second is [1], etc.
  • Ordered: items have a defined order and will not change. Adding new items to a list will be placed at the end of the list.
  • We can change, add, and remove items after it has been created.
  • Duplicates: Lists allow duplicate values.
  • Coord1.append(100) will place 100 at the end of the list.
  • Coord1.insert(2, 250) will insert the value 250 at index 2.
  • Coord1[1:4] = show me values in list between indexes 1 and 3. #Note goes up to but does not include index 4.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Set

A
  • Used to store multiple items in a single variable.
  • Set is a collection which is both unordered and unindexed and do not allow duplicate values.
  • Written with curly brackets.
  • Can convert to a set to get distinct values.
  • Coord1.difference(coord2) – things in coord1 but not coord2
  • Coord1.intersection(coord2) – things in both sets
  • Coord1.union(coord2) – things in either set
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Dict

A
  • Used to store data values in key: value pairs.
  • It is orders, changeable and does not allow duplicates. They are written with curly brackets and have keys and values.
  • Ex: dict = {‘brand’: ‘Ford’, ‘model’: ‘mustang’, ‘year’: 164}
  • Dict[‘brand’] – this will look up the value for the key ‘brand’. This is how to slice in dictionaries.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly