Quiz 1 Flashcards
(28 cards)
len(list)
Returns the length of a list or any collection.
type(variable)
Identifies the type of the variable.
isinstance(variable, type)
Checks if a variable is of a specific type.
append(element)
Adds an element to the end of the list.
insert(index, element)
Inserts an element at a specific position.
pop(index)
Removes and returns an element at the specified index.
sort()
Sorts the list in ascending order.
slice notation [start:stop:step]
Access specific portions of a list.
The first possible position is 0, and the slice will get elements up to, but not including stop.
dict[key] = value
Adds or updates a key-value pair
del dict[key]
Removes the key-value pair with the given key.
dict.pop(key)
Removes and returns the value for the specified key
dict.keys()
Returns a list of all keys in the dictionary.
dict.values()
Returns a list of all values in the dictionary.
set_one.union(set_two)
Returns a new set with elements from both sets.
set_one.intersection(set_two)
Returns a set with elements common to both sets.
set_one.difference(set_two)
Returns elements in set_one but not in set_two.
int()
Converts a value to an integer.
float()
Converts a value to a float.
str()
Converts a value to a string.
bool()
Converts a value to a boolean.
Math Module Functions:
- math.log(x): Returns the natural logarithm of x.
- math.exp(x): Returns the exponential of x.
- math.ceil(x): Rounds x up to the nearest integer.
- math.floor(x): Rounds x down to the nearest integer.
Variable types
integer: whole number
float: not whole number
string: text
boolean: true or false
Tuples
- Tuples are quite similar to lists in that you access elements by position, but they are “fixed.”
- You can’t change the number of elements in the tuple.
- You can’t change the objects stored in each slot.
- The formal term is that they are “immutable”. It is like they are set in concrete.
Container types
– list
– dict
– tuple
– set