Show Menu
Cheatography

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)
 

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.