Python Basics
Data types
"hello world" # string
1729 # integer
17.10 # float
True False # booleanMath
+ # 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 toLogical operators
and
or
notVariables
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 aInputs
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 spaceTerminology
Subscripting
"hello"[0]
# pulling out specific charactersString concatenation
"hello" + "goodbye"Case styles
BlueCar # Pascal case
blueCar # Camel case
blue_car # Snake caseEvent listeners
Code that listens to key presses by the user.
See next
- Python-Control-Flow — if/else + loops
- Python-Functions — defining and calling functions
- Python-Data-Structures — lists, dicts, tuples