Python Basics

Data types

"hello world"    # string
1729             # integer
17.10            # float
True False       # boolean

Math

+    # addition
-    # subtraction
*    # multiplication
/    # division PRODUCES A FLOAT TYPE
//   # division round down to nearest integer
%    # remainder
()   # things in these brackets will be evaluated first, it's not *
 
+=   # continuously add (string also)
-=   # continuously subtract
!=   # not equals to
==   # equals to
>=   # more than equals to
<=   # less than equals to

Logical operators

and
or
not

Variables

Try to use actual words, separated by underscores if needed. Variables cannot start with a number.

apple = "red"
 
a = 0
b = 1
a, b = b, a + b  # using previous a + previous b
 
a = b
b = a + b        # using new a

Inputs

input = ("Your name is: ")
if input:
    print("An input was received")
 
>> An input was received
# If there's an input, input is True.

Formatting

\n   # next line
\t   # tab space

Terminology

Subscripting

"hello"[0]
# pulling out specific characters

String concatenation

"hello" + "goodbye"

Case styles

BlueCar   # Pascal case
blueCar   # Camel case
blue_car  # Snake case

Event listeners

Code that listens to key presses by the user.

See next