HAILEYBURY
BHALUKA
PYTHON PROGRAMMING
2nd Class
Today’s Agenda:
TYPES OF DATA 3 types of data: int, float, str
4 types of Arithmetic Operators and 2 advanced arithmetic
OPERATORS
operators
Assigning, printing and doing arithmetic operations using
VARIABLES
variables
LIST Creating and Printing Lists
Types of Data
1
Integer
It’s a type of numerical data. The type
of numerical data which is a whole
number or doesn’t have any decimal
places are categorized in this type of
data.
It is commonly used as ‘int‘ in
programming
For Example: 13,47
Example in a code:
x=9
print(x)
Result After Running the code:
9
Here, in this code the variable has been
assigned with a value.
This value is a whole number which is the digit
9. It is a type of value, called integer or ‘int’
Float
It’s a type of numerical data. The
type of numerical data with one or
more decimal places are categorized
in this type of data.
It is commonly used as ‘float‘ in
programming
For Example: 13.47
Example in a code:
x = 9.17
print(x)
Result After Running the code:
9.17
In this code the variable has been assigned
with a value.
This value is a decimal number which is 9.17. It
is a type of numerical value, called ‘float’.
String
It’s a type of data. The type of data
which alphabetical and contains
letters are categorized in this type of
data. You should use quotation before
and after this type of data.
It is commonly used as ‘str’ in
programming
For Example: “hello”
Example in a code:
x = “hello”
print(x)
Result After Running the code:
hello
In this code the variable has been assigned
with a text type value.
This value is a word which is “hello”. It is a type
of text or alphabetical value, called string or
‘str’.
Operators
2
Addition
It’s a type of arithmetic operator. This
type of arithmetic operators is used
when you want add the values in a
variables or constants. They can be
used in other purposes too. The
operator used for this operation is ‘+’
For Example:
13+47
a+b
Example in a code:
x=9
y=5
print(x+y)
Result After Running the code:
14
In this code the value assigned in variable x is
added to the value assigned in variable y by
using the operator ‘+’.
Subtraction
It’s a type of arithmetic operator. This
type of arithmetic operator is used
when you want to subtract the values
in variables or subtract constants.
They can be used in other purposes
too. The operator used for this
operation is ‘-’
For Example:
13-47
Example in a code:
x=9
y=5
print(x-y)
Result After Running the code:
4
In this code the value assigned in variable y is
subtracted from the value assigned in variable x
by using the operator ‘-’.
Multiplication
It’s a type of arithmetic operator. This
type of arithmetic operator is used
when you want to multiply the values
in variables or multiply constants.
They can be used in other purposes
too. The operator used for this
operation is ‘*’
For Example:
13*47
Example in a code:
x=4
y=5
print(x*y)
Result After Running the code:
20
In this code the value assigned in variable y is
multiplied by the value assigned in variable x by
using the operator ‘*’.
Division
It’s a type of arithmetic operator. This
type of arithmetic operator is used
when you want to divide the values in
variables or divide constants. They
can also be used in other purposes.
The operator used for this operation is
‘/’
For Example:
12/6
a/b
Example in a code:
x = 20
y=5
print(x/y)
Result After Running the code:
4
In this code the value assigned in variable x is
divided by the value assigned in variable y by
using the operator ‘/’.
Floor Division
It’s a type of arithmetic operator. It is
used when you don’t want any
decimal places after the division
answer. By using the operator ‘//’
For Example:
25//6
The result will be 4 instead of
4.16666667
Example in a code:
x = 25
y=6
print(x//y)
Result After Running the code:
4
In this code the value assigned in variable x is
divided by the value assigned in variable y by
using the operator ‘//’. The result of the division
doesn’t contain any decimal places.
Exponents
It’s a type of arithmetic operator. It is
used when you want to work out
exponents of the value assigned to a
variable or work out exponents of
constants . By using the operator ‘**’
For Example:
3**2
4**2
Example in a code:
x=3
y=2
print(x**y)
Result After Running the code:
9
In this code the value assigned in variable x is
to the power of the value assigned in variable y
by using the operator ‘**’. The values are
exponentiated and the result is 9.
Variables
3
Assigning values to
Variables
A variable is a word or a letter which
can be used for assigning values.
You can assign values like integer,
float, string and many more.
Example in a code:
x=3
print(x)
Result After Running the code:
3
Example in a code:
x = 3.17
print(x)
Result After Running the code:
3.17
Example in a code:
x = “Hello world”
print(x)
Result After Running the code:
Hello world
Mathematical Operations using
Variables
You can do many mathematical
operations using variables. You can
use operations like addition,
subtraction, division, multiplication
etc.
Example in a code:
x = 15
print(x+5)
print(x-5)
print(x*5)
print(x/5)
Result After Running the code:
20
10
75
3.0
Lists
4
List
So, List is also a type of data that can
be used to store multiple items in a
single variable. You can store multiple
types of data in a single variable.
Example in a code:
x = [“hello", “hi", “red", “blue", “white"]
y = [1, 2, 3, 4]
print(x)
print(y)
Result After Running the code:
[‘hello', ‘hi', ‘red', ‘blue’,
‘white’]
[1, 2, 3, 4]
AWESOME
WORDS