1/31
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Required as an input parameter
class Student():
def __init__(self, name)getting data in
Set at instantiation
class Student():
def __init__(self, name)
self.name = nameobject has the data
Instance
An instance is a specific object created from a class or is part of a data type, with its own data and behaviour.
Instance Attribute
def __init__(self, name, cid, year, tutor):
super().__init__(str(name), int(cid)) #calling parent constructor
self.year = year #instance attribute
self.tutor = tutor #instance attribute
self.ace_induction = False #instance attributequality specific to that method relating to the class
An instance attribute is a variable defined in a class using self that stores data specific to each instance of the class.
Class Attribute
class DEStudent():
'''class just for DesEng students'''
Faculty = 'Engineering'bf the def __init__(self) which is a method
A class attribute is a variable defined in a class that is shared by all instances (objects) of that class
Function
def greet(name):
print("Hello", name)Reusable block of code that performs a specific task
Method
class Student:
def __init__(self, name):
self.name = name
def say_hello(self): # ← this is a method
print("Hi, I'm", self.name)A method is a function defined inside a class that operates on instances of that class, typically using self.
Super()
class DEStudent(ImperialStudent):
def__init__(self):
super().__init__(name, cid)where name and cid were defined in an earlier class.
req sub class to have the super class in its brackets
oop
object oriented programming - class, attributes and methods
ssh
secure shell
seaborn
a Python data visualisation library built on top of Matplotlib that provides a higher-level interface for creating attractive and informative statistical graphics
pandas
an extension of Python to process and manipulate tabular data
matplotlib
a Python library that allows users to generate a wide range of static, animated, and interactive visualisations, such as line graphs, bar charts, and scatter plots, from numerical data
num.py
is a Python library used for efficient numerical computing, providing support for arrays, matrices, and mathematical operations on large datasets
Faster than standard Python lists
module
file containing Python definitions and statements; could contain one or more classes; the name of the module is the name of the file (with .py on the end)
isinstance
built-in Python function used to check whether an object is an instance of a specified class or data type
Boolean
Pass by reference
for mutable data, a method of passing arguments to a function where the function receives a reference to the original object, allowing it to modify the original data
pass by value
for immutable data, a method of passing arguments where a copy of the value is passed to the function, so changes made inside the function do not affect the original variable
mutable
object whose value can be changed after it is created
iterators
An iterator is something that lets you go through a collection one item at a time.
numbers = [10, 20, 30]
it = iter(numbers) # create iterator
print(next(it)) # 10
print(next(it)) # 20
print(next(it)) # 30.append
a list method in Python that adds a single element to the end of a list
df
DataFrame (df) is a two-dimensional data structure in Python (from the pandas library) used to store and manipulate tabular data with rows and columns
df.head()
Prints the first few rows of the data
df.info()
Shows you the columns, if any columns have null data, and the variable type of each column
df.shape
Will give you the size of the data (number of rows x number of columns)
df.mean()/.median()
Gives you the average value of each column
df.std()
Gives you the standard deviation of each column
df.unique()
Gives you the standard deviation of each column
whitespace sensitive
A language where spaces, indentation, and newlines affect the syntax. In Python, indentation defines code blocks.
Dictionaries
dictionary_name = { 'key_1': 'value_1', 'key_2': 'value_2', 'key_3': 'value_3'}
print(dictionary_name.get('key_1')) # 'value_1'
dictionary_name['key_1'] = 20 # update
dictionary_name['key_4'] = "A" # add new key-value pair
for key, value in dictionary_name.items():
print(key, value)
student.keys() # returns all keys
student.values() # returns all values
student.items() # returns (key, value) pairs
student.clear() # empties dictionaryoutput:
‘value_1’
'key_1' 'value_1'
‘key_2' 'value_2'
'key_3' 'value_3'
‘key_4’ ‘A’
len()
for a string
len('hello') #5gives number of characters
for a list
numbers = [1, 2, 3, 4]
len(numbers) #4gives # items
for dictionaries
dict = { 'name': 'Sally', 'age': 19}
len(dict) #2 gives number of key-value pairs