Deck 1 Flashcards
#
Comment – anything after this does not get read by computer
print()
Print function. Computer will “speak” the words inside this, as long as there are quotation marks around the words
strings
Blocks of text. Must have either “double” or ‘single’ quotation marks around them. Must be consistent with either double or single all the way through.
variable
Assigns string of data to this using equal sign. Data is stored for later use. Must use quotation marks for strings. this = “the string of data to be stored”
print(this) –outputs– the string of data to be stored
variable rules
Can’t have spaces or symbols other than underscore (_). Cannot begin with number, although can have numbers in it.
reserved words a
and
as
assert
reserved words b
break
reserved words c
class continue
reserved words d
def del
reserved words e
elif
else
except
reserved words f
finally
for
from
reserved words g
global
reserved words i
if
import
in
is
reserved words l
lambda
reserved words n
nonlocal
not
reserved words o
or
reserved words p
pass
reserved words r
raise
return
reserved words t
try
reserved words w
while
with
reserved words y
yield
> > >
interactive chevron prompt. this prompt is the Python interpreter’s way of asking you, “What do you want me to do next?” Python is ready to have a conversation with you.
quit()
the proper way to say “good-bye” to Python. enter at interactive chevron prompt.
script
python file
.py
file extension for python scripts, what python files are saved as
$
operating system prompt
numbers
numbers without quotation marks make them math-y and can be used in math operations
+
adds stuff together, both numbers and words
-
subtracts stuff
*
multiplies
/
divides
reserved words
we must use these words to mean the thing that python expects them to mean, so we cannot use them in variables or such
len()
function that tells you how many characters are in a string OR how many items are in a list
print(len(list))
print(len(string))
integers
whole numbers (including negatives)
float
numbers with decimals, or fractions, etc.
int()
converts a string to a number
boolean
term for a value that is either True or False, or Yes or No
True
equal to 1
False
equal to 0
boolean expression
a combination of booleans (and comparison operators) that evaluates to True or False, or Yes or No
and
A boolean operator. An expression with ‘and’ evaluates to True if and only if both parts of the expression are True
or
A boolean operator. True if either side of the expression is true.
not
Negates a boolean value and makes it the opposite of whatever it currently is
if
If statements. They allow a python program to make decisions based on boolean expressions. The code following keyword if must be a boolean expression.
if boolean statement : (equates to true or false)
print(‘whatever’) executes “then statement” if true
code is executed in an if statement
when the condition is True
elif
chains multiple conditions together if elif elif (only one value outputs, not all three as would happen if all were if)
else
when if condition is false, else block will be executed
added at end of an if block
statement
if statement :
then statement (runs if true)
else :
then statement (runs if false)
final statement