Show Menu

Python Cheat Sheet by

Intera­cting with the user

print a message
print(­"­Hello, World!­")
asking the user for a string
print(­"What is your name? ")
Defini­tions:

strings – assigning a value to a variable

Options in Python

X = 3
If X == 3:
print(­"x is 3")

Number = 80
If Number >= 50:
print(­"­Clo­se")

Elif Number < 50:
print(­"­Far­")

Else:
print ("too far")
 

Text

single quoted
'example'
double quoted
"­exa­mpl­e"
multi-line
' ' ' Hello,
concat­enating strings (adding strings together)
'Hello' + 'World'
converting strings to integers
int('467')
Defini­tions:

integers – positive or whole numbers with no decimal point

Variables

creating a variable
name = "­Lis­a"
using a variable
print(­"My name is ") + name
Defini­tions:

variable – can be used to store data like integers, decimals, and charac­ters.

Maths in Python

addition and subtra­ction
2 + 2 - 3
multip­lic­ation and division
10*5/5
Powers (e.g. x to the power of y)
3**5
Converting integers to strings
str(511)

Download the Python Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/lhedes_python.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.