Python reviewer
Python reviewer
input()
#takes an input from the user
print()
#outputs whatever is in the parentheses
#random text
#Lines following a hashtag will become comments and the will be ignored by the program but
can be seen by you
x=213, x=”Chris”
#Creates a variable (x and the values are placeholders and can be anything). Multiple value
variables also exist as see below
X,y,z =”Hi”,”Hello”,”Kamusta”
#Creates multiple variables with the first value being assigned to the first variable, the second
value to the second variable and so on
Data types
Str
#The data type used for characters which can be anything
Int
#integers
Float
#numbers with decimal points
Range
#description below
List
#description below
Tuple
#description below
Set
#description below
Typecasting
Is converting strings to other data types by enclosing them in the desired data type, for example:
x=int(input())
#the data type of the input is now int instead of str
Sequence types
Tuples are lists that are unchangeable and use ( ) instead of [ ]. For example:
The x is simply a variable and how the function works is that it will return the numbers from the
start value until the number before the stop value. The step value determines the difference
between each value. For example
for i in range(1, 10, 2):
print(i)
Output:
1
3
5
7
9
Thislist.append(“element”)
#Adds an element to the end of the list
thislist.remove(“element”)
#removes an element from the list
Set
Storage of multiple, unordered, unindexed, unchangeable values in one variable
thisset={“uno”,”dos”,”tres”}
thisset.add(“quatro”)
#adds an element
thisset.remove(“uno”)
#removes an element
Dictionaries
Storage of multiple values with no duplicates
To create:
thisdictionary = {
“name”:”Jojo”,
“subject”:”Math AA HL”,
“status”:”failing”
To access:
print(thisdictionary[“name”])
To change value:
thisdictionary[“name”]=“Javy”
thisdictionary.pop(“status”)