This is a draft cheat sheet. It is a work in progress and is not finished yet.
Basic Syntax
Adding Comments |
# Followed by Text |
Specifying Variables |
x = 3 or x, y = (1, 2) |
Specifying Equality |
== |
Line Continuation |
\ |
Printing Strings |
print("Text") |
Specifying Inequality |
!= |
Variable Types
Integers |
int(x) --> 5 |
Floats |
float(x) --> 5.0 |
Strings |
string(x) --> Text |
Arithmetic Operators
Addition |
+ |
Subtraction |
- |
Multiplication |
* |
Division |
/ |
Exponents |
** |
Logarithms |
math.log(x/y) |
Radicals |
math.sqrt(x) |
Install advanced math tools using import math
Comparison Operators
Greater Than |
> |
Less Than |
< |
Greater Than or Equal |
≥ |
Less Than of Equal |
≤ |
Logical Operators
and |
Two True Statements |
or |
One True One False |
not |
Two False Statements |
|
|
Conditional Statements
if x > 5:
print("x is bigger")
elif: x < 5:
print("x is smaller")
else:
print("x is equal")
|
if sets condition, elif sets if first condition not true, else sets condition if remainder is false
Defining a Function
Option 1:
def plus_five(x):
return x+5
plus_five(x)
Option 2:
def five_plus(x):
result = x+5
return result
plus_five(x) |
Defined function name, returned function form, executed function. We can print text as well as results by using the print function
Composite Functions
def wage(hrs):
return 25*hrs
def with_bonus(hrs):
return 50 + wage(hrs)
wage(40), with_bonus(40)
(1000, 1050)
|
Composite Functions
def wage(hrs):
return 25*hrs
def with_bonus(hrs):
return 50 + wage(hrs)
wage(40), with_bonus(40)
(1000, 1050)
|
|
|
|