Python Cheat Sheet

A Programming › Python cheat sheet in English by lhedes
11,571 views 3,059 downloads 29 Nov 2015 History
3.7 avg · 0 ratings

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
'­exa­mpl­e'
double quoted
"­exa­mpl­e"
multi-line
' ' ' Hello,
concat­enating strings (adding strings together)
'­Hel­lo' + '­Wor­ld'
converting strings to integers
int('46­7')
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)

Badges

Good Cheat Sheet Nice Cheat Sheet

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.