2 Flashcards
Python: The lines within each block ( : ) must be
Indented e.g.
if var_1 == True:
print(“its true”)
break
Python: The function that places a value in the {} placeholder is
str.format(“value”) e.g. print(“my name is {}”.format(“Alen”))
Python: For a while loop, typing “while True:” will cause it to
loop forever, unless you add a “break” e.g.
if var_1 == 5
break
Python: For loops, the statement that will cause the loop to return to the top, without continuing the rest of the loop is called
continue
Python: To iterate/loop on every value in a list, use
for made_up_var in list_var:
print(made_up_var)
Python: Python stripts run in sequence so
Do not try to use a variable that only gets assigned later in the script
Python: For functions with arguments you must
Send in a value or else you will get an error
Python: An argument, with regards to functions, is
A value you pass into the function when you run it. e.g. my_function(argument1, argument2)
Python: You must tell a function what values to return by typing
return var_1, var_2
Python: functions start with the word
def
Python: function names should only use
lower case letters and underscores
Python: To add another if statement after the first one use
elif e.g.
elif var_1 == “SHOW”:
show_list()
continue
Python: After defining a function, to run it you must
call it e.g. my_function(argument)
Python: To import a python library, type
import name_of_library, into the python interpreter or top of script
Python: To call the “choice” method form the “random” library, type
random.choice()
Python: Can you create a new variable inside a function
Yes
Python: It’s recommended to do all the imports
at the beginning of the script
Python: It’s recommended to do the imports
at the beginning of the script
Python: You can imbed if and else commands
inside other if and else commands
Python: To get an automatic list of numbers starting from zero, type
list(range(10))
Python: You cannot reference variables outside of a function
From within the function. You must pass it in.
Python: To assign multiple variables simulaneously, type
var_1, var_2 = “Phil”, “Bill”
Python: Values on the right side of a variable always get
Evaluated first
Python: To insert a list into the middle of another list, type
list_1.insert(4, list_2)
The 4 denotes the index to insert at