algo Flashcards
python: To declare a variable without assigning it a value, type
my_variable = None
algo: For a linked list, the main 2 attributes you need are
data and next
python: To make the most basic class, type
class MyClass: pass
python: Every file that you create is a
library
python: To import one specific class from an external file, type
from library_name import ClassName
python: To turn two lists into a dictionary, type
dict(zip(list1, list2))
python: To slice the last 8 characters from a string, type
my_string[-8:]
python: To round a number to the nearest whole number, type
round(1.3)
python: To make a one line if else statement, type
“true value” if 10==10 else “false_value”
python: To make a node of a linked list that takes in its data upon instantiation, type
class Node: data = None next = None def \_\_init\_\_(self, data): self.data = data
python: To call a class method on the class itself, type
ClassName.method_name(class_instance)
python: To import a class called MyClass from a file called my_file.py in the current directory, type
from my_file import MyClass
python: All class methods must have a
self argument
python: To call a class variable from inside a class method, type
self.variable_name
python: To call a class method from inside another class method, type
self.method_name()