1/34
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Sets
A collection data type made up of unordered elements
Curly Braces or {}
To specify sets you can use the
set()
To create sets you can use
len()
To check length you can use
add()
To add elements you can use
remove()
To delete elements you can use
in keyword, it will return a Boolean value
To check if a set contains a specific value use
Union (Vertical Bar)
Creates a union of two sets
Intersection (Ampersand&)
Gets the common elements between sets
Difference (-)
Gets the elements of the first set that are not in the second set
Exclusive (Caret^)
Gets all the elements in both sets except the intersecting values
Subset (<=)
Checks if the elements of first set are found in the second
Proper Subset (<)
Checks if the second set contains all the elements of the first and more
Superset (>=)
Checks if all the elements of the second set are found in the first
Proper Superset (>)
Checks if the first set contains all the elements of the second and more
Frozensets
Sets with immutable values
frozenset()
To specify a frozensets use
Dictionaries
A collection data type that consists of key and value pairs
dict()
To specify a dictionary use
dict() and zip()
Can also use to combine two lists are
get() method.
You can also get the value of a key using the
keys()
You can get the keys using
dict_keys()
A dictionary view object that supports iteration
dict_values()
To make a list out of the result use
items()
To export elements to the list composed of of key value tuples use
Conditionals: use if
Allow you to execute lines of code if particular conditions are met.
Nesting Conditions: elif
You can place other statements within conditions
Logical operators
Can also be used to check if conditions are met
Loops
It is when programming tasks can be repetitive.
While
keyword allows us to execute code over and over
for and in
To create loops we can use
break keyword
When you want to loop something indefinitely until conditionals met use
continue keywords
skips running the code for an iteration
range()
To create a sequence of numbers use
input()
To allow some interactions with a user use