1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Namespace
a collection of names and their associated objects or mapping between variable names and python object (like a dictionary)
can change depending on where you are in your program
can store names of variables, functions and classes
currently defined symbolic names and information about an object
Variable
pointers that "point" to objects.
flag or name of an area of memory (‘object’)
Class
like an object constructor, or a "blueprint" for creating objects
Objects have different attributes and respond in different ways to built-in functions
Can be used to store information
Certain names or identifiers can never be used (False, else, if, etc… has its own meaning)
Data Types/Classes
float - a real number w/ a fractional part
int - used for integers.
str - used for texts. We can define strings using single, double, or triple quotes. They’re also used for writing function documentation.
bool - used for truth/false values. Useful to perform a filtering operation on a data.
list - used to store a collection of values.
dict - used to store a key-values pairs.
complex - complex number such as 5i
List
an ordered, changeable sequence or data structure. Use when order matters and you'll add, remove, or reorder items.
numbers = [1, 2, 3]
Lists are not meant for math! They don’t have a datatype.
Tuple
an ordered sequence that can't be changed after creation. Good for fixed groupings like coordinates
raw_data = (1, 2, 3)
point(3, 4)
Index
the numerical position of an item within an ordered sequence, such as a list, string, tuple, or range
my_list[0][1] with the “0” being the item in the list and the “1” being the position of the letter/number in the item
negative indexing exists, with -1 referring to the last letter/number in a term
python counts from ZERO
Inclusivity
Python is left-inclusive and right-exclusive when using ranges and slicing.
How It Works
• Left side (Start): Included in the result.
• Right side (Stop): Excluded from the result.
Conditionals
if and while statements
also elif, else, for
Comparison Operators
a symbol that allows you to compare two values and return a Boolean result: either True or False
== equal to
!= not equal to
< less than
> greater than
>= greater than or equal to
<= less than or equal to
and
or
Loop
programming construct that allows a block of code to be executed repeatedly until a certain condition is met
Iterates over any iterable — list, string, range, tuple, dict, file, etc.
range(n) generates numbers 0 to n−1
for i in range (5) = 0, 1, 2, 3, 4
break exits early, continue skips to the next item
Functions
a piece of reusable code solving a specific task
can create functions using: def function_name()
can be created or built in already to python
take some inputs (“arguments”) and do something in response
Methods
function that is available for a given object depending on the object’s type.
Data Structures
a way of organizing and storing data so you can access and change it efficiently, may have specific operators that work on them.
ex) Int, Float, Str, Lists, Tuples
Boolean Logic
a form of algebra where all variables and values are strictly limited to one of two states: true (1) or false (0)
Dictionaries
maps keys to values, unordered
d = {‘name’: ‘Ryan’, ‘number’: 2}
d = dict(name='Takaya', age=25)
to access a value type: d['name']
Pure function
Functions that don’t modify their arguments or produce any other side-effects
Impure function
Functions that modify their arguments or cause other actions to occur
Magic/dunder method
special methods that begin with double-underscores, which allow us to customize the behavior of our classes.
Slicing
The first character has index 0
Slice To the End: print(b[2:])
Get the characters from position 2, and all the way to the end
Slice From the Start: print(b[:5])
Get the characters from the start to position 5 (not included)