Show Menu
Cheatography

Python Section 1-9 Cheat Sheet (DRAFT) by

Udemy Course Overview

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 Contin­uation
\
Printing Strings
print(­"­Tex­t")
Specifying Inequality
!=

Variable Types

Integers
int(x) --> 5
Floats
float(x) --> 5.0
Strings
string(x) --> Text

Arithmetic Operators

Addition
+
Subtra­ction
-
Multip­lic­ation
*
Division
/
Exponents
**
Logarithms
math.l­og(x/y)
Radicals
math.s­qrt(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
 

Condit­ional 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_f­ive(x):
return x+5
plus_f­ive(x)

Option 2:
def five_p­lus(x):
result = x+5
return result
plus_f­ive(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)