PYTHON CHEAT SHEET
100 DAYS OF CODE
COMPLETE PROFESSIONAL
PYTHON BOOTCAMP
BASICS
Print
Prints a string into the console. print("Hello World")
Input
Prints a string into the console, input("What's your name")
and asks the user for a string input.
Comments
Adding a # symbol in font of text #This is a comment
lets you make comments on a line of code. print("This is code")
The computer will ignore your comments.
Variables
A variable give a name to a piece of data. my_name = "Angela"
Like a box with a label, it tells you what's my_age = 12
inside the box.
The += Operator
This is a convient way of saying: "take the my_age = 12
previous value and add to it. my_age += 4
#my_age is now 16
www.appbrewery.com
, PYTHON CHEAT SHEET
100 DAYS OF CODE
COMPLETE PROFESSIONAL
PYTHON BOOTCAMP
DATA TYPES
Integers
Integers are whole numbers. my_number = 354
Floating Point Numbers
Floats are numbers with decimal places. my_float = 3.14159
When you do a calculation that results in
a fraction e.g. 4 ÷ 3 the result will always be
a floating point number.
Strings
A string is just a string of characters. my_string = "Hello"
It should be surrounded by double quotes.
String Concatenation
You can add strings to string to create "Hello" + "Angela"
a new string. This is called concatenation. #becomes "HelloAngela"
It results in a new string.
Escaping a String
Because the double quote is special, it speech = "She said: \"Hi\""
denotes a string, if you want to use it in print(speech)
a string, you need to escape it with a "\"
#prints: She said: "Hi"
www.appbrewery.com
, PYTHON CHEAT SHEET
100 DAYS OF CODE
COMPLETE PROFESSIONAL
PYTHON BOOTCAMP
F-Strings
You can insert a variable into a string days = 365
using f-strings. print(f"There are {days}
The syntax is simple, just insert the variable in a year")
in-between a set of curly braces {}.
Converting Data Types
You can convert a variable from 1 data n = 354
type to another. new_n = float(n)
Converting to float:
float() print(new_n) #result 354.0
Converting to int:
int()
Converting to string:
str()
Checking Data Types
You can use the type() function n = 3.14159
to check what is the data type of a type(n) #result float
particular variable.
www.appbrewery.com
100 DAYS OF CODE
COMPLETE PROFESSIONAL
PYTHON BOOTCAMP
BASICS
Prints a string into the console. print("Hello World")
Input
Prints a string into the console, input("What's your name")
and asks the user for a string input.
Comments
Adding a # symbol in font of text #This is a comment
lets you make comments on a line of code. print("This is code")
The computer will ignore your comments.
Variables
A variable give a name to a piece of data. my_name = "Angela"
Like a box with a label, it tells you what's my_age = 12
inside the box.
The += Operator
This is a convient way of saying: "take the my_age = 12
previous value and add to it. my_age += 4
#my_age is now 16
www.appbrewery.com
, PYTHON CHEAT SHEET
100 DAYS OF CODE
COMPLETE PROFESSIONAL
PYTHON BOOTCAMP
DATA TYPES
Integers
Integers are whole numbers. my_number = 354
Floating Point Numbers
Floats are numbers with decimal places. my_float = 3.14159
When you do a calculation that results in
a fraction e.g. 4 ÷ 3 the result will always be
a floating point number.
Strings
A string is just a string of characters. my_string = "Hello"
It should be surrounded by double quotes.
String Concatenation
You can add strings to string to create "Hello" + "Angela"
a new string. This is called concatenation. #becomes "HelloAngela"
It results in a new string.
Escaping a String
Because the double quote is special, it speech = "She said: \"Hi\""
denotes a string, if you want to use it in print(speech)
a string, you need to escape it with a "\"
#prints: She said: "Hi"
www.appbrewery.com
, PYTHON CHEAT SHEET
100 DAYS OF CODE
COMPLETE PROFESSIONAL
PYTHON BOOTCAMP
F-Strings
You can insert a variable into a string days = 365
using f-strings. print(f"There are {days}
The syntax is simple, just insert the variable in a year")
in-between a set of curly braces {}.
Converting Data Types
You can convert a variable from 1 data n = 354
type to another. new_n = float(n)
Converting to float:
float() print(new_n) #result 354.0
Converting to int:
int()
Converting to string:
str()
Checking Data Types
You can use the type() function n = 3.14159
to check what is the data type of a type(n) #result float
particular variable.
www.appbrewery.com