Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Python Reference

The table below shows some of the key terms you might need to know.

Keyword Meaning
Variable A named piece of data whose value can change
Assignment The process of giving a value to a variable
Syntax The rules of a language
Error When something goes wrong in a program
Condition A statement that we can check that is either true or false, used for making
decisions.

The table below shows you what some basic Python commands do.

Code What does it do?


num = 3 Creates a variable called num and sets its value to 3
text = "hello" Creates a variable called text and sets its value to
"hello" (note that we need to put " " marks around
text)
x = 3 + 4 Creates a variable called x and sets its value to the result
of 3 plus 4.
y = x – 5 Creates a variable called y and sets its value to the result
of x minus 5.
x = 2 * 4 Creates a variable called x and sets its value to the result
of 2 times 4.
z = x / y Creates a variable called z and sets its value to the result
of x divided by y.
print(var) Displays the value of a variable called var to the screen
int("6") Turns the string "6" into the integer 6
str(4) Turns the integer 4 into the string "4"
name = input("Name: ") Creates a variable called name and sets its value to
whatever the user enters after displaying the message
"Name: ". The input function always makes a string,
even if the user types in a number.
if(4<2): Prints "One" if the condition 4 < 2 is true. Prints "Two" if
print("One") the conditions 4 > 2 is true. Prints "Three" if none of the
elif(4>2): conditions are true. If more than one conditions is true,
print("Two") only the code for the first true condition will run.
else:
print("Three")

The table below shows you some of the basic data types in Python.

Data type Explanation Example


Integer A whole number num = 18
String Text text = "Python"
Float A number with a decimal point num = 4.65
Boolean A value that is either True or False bool = True
Online Help
Variables:
https://beginnersbook.com/2019/03/python-variables/

If statements:
https://beginnersbook.com/2018/01/python-if-statement-example/

https://beginnersbook.com/2018/01/python-if-else-statement/

https://beginnersbook.com/2018/01/python-if-elif-else/

You might also like