Definitions Flashcards
way of organizing data so it can be accessed more
Data structures
organize and group data according to type
containers
a collection of ordered, changeable, allows duplicate,
- a very flexible becasue it can contain different data types
List
ordered, unchangeable, allows duplicate
-a collection of Python objects like a list but are immutable
Tuple
unordered, unchangable, unindexed, does not allow duplicate
-used to include membership testing
-used to eliminating duplicate entries
Set
ordered, changeable, and does not allows duplicate
-holds a key:value pair
-cannot have two items with the same key
Dictionary
an object that can never change like strings, numbers and tuples etc.
key
adds an element at the end of the list
append()
removes all the elements from the list
clear()
returns a copy of the list
copy()
returns the number of the elements with the specified value
count()
add the elements of a list(or any iterable or can be enumerate into 1) to the end of the urrent list
extend()
returns the index of the first element with the specified value
index()
adds element at the specified position
insert()
removes the element at the specified position
pop()
removes the item with the specfied value
remove()
reverses the order of the list
reverse()
sorts the list
sort()
adds an elements to the set
add()
removes all the elements to the set
clear()
returns a copy of the set
copy()
returns a set containing the difference between two or more sets.
difference()
removes the items in the set that are also included in another, specified set
difference_updated()
removes the specified items
discard()
returns a set, that is the intersection of two other sets
intersection()
removes the items, in this set that are not present in other, speciied sets
intersection_updated()
returns whether two sets have a intersection or not
indisjoint()
returns whether another set contains this set or not
issubset()
returns whether this set contains another set or not
isuperset()
removes the elements to the set
pop()
removes the specified element
remove()
returns a set with the symmetric differences of two sets
symmetric_difference()
inserts the symmetric differences from this set and another
symmetric_difference_update()
returns a set containing the union of sets
union()
update the set with union of this set and others
update
removes all the elements from the dictionary
clear()
returns copy of the dictionary
copy()
returns a dictionary with the specified keys and value
fromkeys()
returns the value of the value of the specified key
fromkeys()
returns a list containing a tuple for each key value pair
items()
returns a list containing the dictionary’s key
keys()
removes a list containing the specified keys
pop()
removes the last inserted inserted key-value pair
popitem()
returns the value of the specified key. If the key does not exist:insert the key, with sepcified value
setdefault()
updates the dictionary with the specified key-value pairs
update()
returns a list of all the values in the dictionary
values()
a block of code that can only executes when called
-where data can be passed
-can return data as a result
python function
a keyword used to define a function
def
a function definition
def sample_function():
a fucntion call
sample_function()
information passed into a function
-specified after the function name and inside the parenthesis
- seperated by comma
Arguments or args
a function perspective that the variable inside the parenthesis in the function definition
parameter
a function perspective that the value sent to the function when called
argument
the order of arguments does not matter
keyword arguments or kwargs
a function call itself
recursion
the three specific region where a variable can be accessed
local
nonlocal
global
it is created inside the add_num function and can only be accessed within (local)
variable scoop
a keyword to create a nonlocal variables
-used in nested functions when local scope is not defined
nonlocal
what is called a random module that can be used to generate a random numbers
Random number(import random)
a small anonymous function
-can take any numbers of arguments, but can only have one expression
(lambda arguments: expression)
used as an
used this if anonymous function is needed
lambda
running a block of code based on a particular decesion
programming statements
used to declare a block
identation
used to test a specific condition, if the condition is true
-the condition can be any valid logical expression
if statement
if the condition in the statement is false, it will execute the else statemnt
if-else statement
checks multiple condition and executes the block of code that is evaluated to be true
-optional like else
-can contain multiple elif after an if
elif statement
allows the use of another if statment inside an if
nested if
used to iterating on a sequence (either list or a tuple etc.)
-set of statemnts may be excuted once for each item, tuple, sets etc.
-does not require an indexing varibale to set beforehand
for loop
can stop the loop before it has looped through all items
break
can stop the current iteration of the loop and continue to the next
continue
returns a sequence of numbers from 0 increments by 1, and ends at a specified number
range() function
block of statements to be excuted when the loop is finished
else in for Loop
a loop inside the loop
-the inner loop will be executed once per iteration of the outer loop
nested loop
for loop cannot be empty
pass statement
it can execute a block of statement as long as it true
- needs to define an indexing varibale increment ot decrement this variable or the loop will not end
while loop
the loop can be stopped even if the while condition is still true
break statement
stop the current iteration and continue with the next
continue statement
can run a block of code when the condition is no longer true
else statement
can run at least once
- pyhton does not have a built in of this
- but it is possible to emulate
do-while loop
test if the condition is true or false and retuns the corresponding value, all in one of code
ternary opeartor/conditional operator