You are on page 1of 2

Tuple

A tuple is a form of list that cannot be changed


This property makes it immutable

When defining a tuple instead of [] u will use ()


Even though u cannot modify a tuple
U can always assign new values to it
E.g., Tuple a = (a, b, c, d)
U can modify it by replacing the figures
Tuple a = (E.g.,)

Lists
A list is a collection of items in a particular order
It is represented by [], items are separated using a (,)

In accessing elements, we enter list name ff by position n


So, x_ [n]
X_ is list and n is number
Note in python numbering starts from 0-inf

In inserting elements same is done but, in this case, u assign a variable


So, x_[n] = variable

In removing u access an element then use del in front of it


Or u can use the pop() method
X_.pop()
This removes the last variable

IF STATEMENTS
If statements allow u to check a certain condition
And act accordingly

Before an if statement is made there must first be a for loop


Checking for in equality
To check if two items or values are in equal u combine ! and = so (!=)
But if checking for numbers you can use mathematical equations

To check if an item is in a list we use (in)


Same for the inverse u then use not

Boolean expression or value that evaluates whether an expression is true or false

IF STATEMENTS
Simple statements : perform only one function or test

If-else statements : this allows u to perform one test and if that fails the else
Block executes another test if the first one fails

If-elif-else chain : this allows it to run the tests till one passes

DICTIONARIES
This is a superset of a list that can pair lage amounts of data
It can also contain a lot of info

Dictionary in python is a collection of key value pairs.


Each key is associated with a value, the value can be a string ,list or another dictionary
the key-vaIue is denoted in braces,{} with the key- value pairs
so for example,
alien1 = [colour : green , point : 5]

You might also like