Codecademy Python 1 Flashcards
Float definition
a number with a decimal
Integer definition
a number with no decimal
How to yield a float instead of an integer
Change either a numerator or denominator to be a float (add a period)
Yielding a float example
quotient 1 = 7./2
quotient 2 = 7/2.
The float method example
quotient 1 = float(7)/2
Operator for combining a string with variables
“%s” % ()
Combining string with variables example
name = “Mike”
print “Hello %s” % (name)
Operator for combining a string with variables python 3
”{}” .format ()
Combining strings with variables example Python 3
name = “Mike”
print (“Hello {}”.format (name))
Padding a variable with zeroes
%02d
Function to print the date and time in a nice format
datetime
Importing datetime
from datetime import datetime
Program to print the current date and time
now = datetime.now()
print now
Equal to
==
Not equal to
!=
Less than
Less than or equal to
<=
Greater than
>
Greater than or equal to
> =
Order of operations for Boolean operators
not, and, or
A conditional statement that does something after seeing if its expression is True
if
A statement that is run if the “if” statement is false
else
A statement that runs if the previous expression is false but the following statement is true
elif
Function to check if a string is only letters
.isalpha()