1/49
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What are tuples
a collection of data that is immutable
How to create a tuple
coordinates = (1, 2, 3, 4)
What are named tuples
they allow the programmer to define a new data type that consist of named attributes
How to create a named tuple
name1 = namedtuple("name1", ["detail1", "detail2", "detail3"])
What is a set
an unordered collection of unique elements
How to create a set
nums1 = set([1, 2,3])
How to create a set literal
nums1 = {1, 2, 3}
Does indexing in sets work?
No, because the sets are unordered
How to find the number of elements in a set
len(set)
How to add elements in set2 to set1
set1.update(set2)
How to add value into the set
set.add(value)
How to remove value from the set
set.remove(value)
How to remove a random element from the set
set.pop()
How to clear all elements from the set
set.clear()
What are dictionaries
they contain references to objects as key-value pairs
Syntax for creating dictionary
dict(reference="pair", reference1="pair2")
dict([("reference", "pair"), ("reference2, "pair2")])
how to retrieve the value associated with a key
my_dict[key]
how to add an entry
my_dict[key] = value
how to delete the key from the dictionary
del my_dict[key]
how to test for existence of key in my_dict
key in my_dict
how to remove all items from the dictionary
my_dict.clear()
How to read the value of the key from the dictionary
my_dict.get(key, default):
How to merge dictionary1 with dictionary2
my_dict.update(my_dict2)
my_dict.pop(key, default)
removes and return the key value from the dictionary
How to return a view object that only yields (key, value)
dict.item()
How to return a view object that yields dictionary keys
dict.keys()
How to return a view object that yields dictionary values
dict.values()
How to open a file
open()
How to close a file
file.close()
how to return the file contents as a string
file.read()
How to return a list of strings
file.readlines()
How to write a string argument to a file
file.write()
How to open the file for reading
open("file_name", "r")
How to open the file for writing
open("file_name", "w")
How to open the file for appending
open("file_name", "a")
What is error-checking code
code that a programmer introduces to detect and handle errors that occur while the program executes
What is a try block
code that could be potentially ran
What is an except block
any error that occur, the code is run through here
What is EOFError
input() hits an end-of-file condition without reading any input
What is KeyError
a dictionary key is not found in the set of keys
What is ZeroDivisionError
cannot be divided by zero
What is ValueError
invalid value
What is IndexError
index is out of bounds
What is raise
used to detect an error and cause an immediate exit from the try block
What is a class
user defined type of object containing groups of related variables and functions
What is attribute
the data and behavior of the class
What is an instance
an individual object of the given class
How to create a class?
class ClassName:
def __init__(self):
self.attribute1
self.attribute2
What is method
the function defined within a class
How are attributes accessed?
through dot notation