Simple Python Data Flashcards
Value
A fundamental thing that a program manipulates like a word or number.
Type of data
Numbers and strings print type(5) print type("Hello World! ")
Conversion
print 3.14, int(3.14)
Variable
A variable is a name that refer to a value
message = “What’s up, Doc?”
n = 17
pi = 3.14159
print message
print n
print pi
Keyword
Have different function, can't be use as variable name and as assert break class continue def del elif else except exec finally for from global if import in is lambda nonlocal not or pass raise return try while with yield True False None
Statement
is an instruction that python can execute
Expression
combination of values, variables, operators and calls to function print 1 + 1 print len(“hello”)
Operator
special tokens that represent computations
20 + 32
hour - 1
hour * 60 + minute
minute / 60
(5 + 9) * (15 - 7)
5 ** 2 # ** is the exponentiation operator
7 // 3 # // is the integer division operator
7 % 3 # % is the modulus (or integer remainder) operator
Input
name = raw_input(“Enter your name: “)
print “Hello”, name
Note that the input from raw_input is a string so you may have to convert it by int( )
Updating variables
x = 6 # initialize x
print x
x = x + 3 # update x
print x