0% found this document useful (0 votes)
7 views17 pages

Introduction To Python Programming

This document provides an introduction to Python programming, covering essential topics such as the print method, comments, variables, data types, arithmetic operators, and operator precedence. It explains how to use variables to store data, the different data types available in Python, and demonstrates arithmetic operations with examples. Additionally, it includes exercises for practice and introduces compound assignment operators.

Uploaded by

maythwezin021
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views17 pages

Introduction To Python Programming

This document provides an introduction to Python programming, covering essential topics such as the print method, comments, variables, data types, arithmetic operators, and operator precedence. It explains how to use variables to store data, the different data types available in Python, and demonstrates arithmetic operations with examples. Additionally, it includes exercises for practice and introduces compound assignment operators.

Uploaded by

maythwezin021
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to python

programming

[Link] Oo (Lecturer)
Outlines
▪ Print method
▪ Comments

▪ Variable

▪ Data Type

▪ Expression

▪ Arithmetic Operator

[Link] Oo (Lecturer)
2
Print()
▪ to print use print method

print(10)

print(20)

print(“hello”)

[Link] Oo (Lecturer)
3
Comment

▪ The # symbol is used for writing a comment.


▪ The comments are notes that are ignored by the computer
▪ These to help you read the code and understand
▪ You just put hashtag (#) in front of the text you want to comment.

[Link] Oo (Lecturer)
4
Variable
▪ The variable name is a named location used to store data in the
memory.
▪ variable as a box to store toys in and those toys can be replaced at
any time.
▪ num = 10
print(num)
▪ name = “Mg Mg”
print(name)

5
[Link] Oo (Lecturer)
Variable (Cont’d)
▪ a variable name can be almost anything you want, with a few
exceptions.
▪ You can’t name them something that is already a word in
python. (keyword)
▪ Two variables with the same name in the same block of code can
not use
▪ The same name for two variables in Python, but the value will be
based on the latest assignment.

6
[Link] Oo (Lectuer)
Data type
▪ There are various data types in Python.
▪ Numeric – Integer and floating-point numbers. They are defined as int
and float respectively.

number = 12 # this is an example of int


decimalNumber = 12.543243 # this is an example of float
print(type(number))

7
[Link] Oo (Lecturer)
Data type
▪ Numeric Type
int Integer number x=10
float Floating y=3.14
complex complex z = 2+3j
▪ Complex -> scientific engineering quatum physis
a = 3+2j
b = 1+7j
print(a+b)
print(a-b)
8
[Link] Oo (Lectuer)
Data type
▪ Text Type
string name = “mgmg” string of character
▪ Boolean Type
bool logical value True/False flag=True

[Link] Oo (Lecturer)
9
Arithmetic Operators

▪ Arithmetic Operator
+ - * / % // **
num1 = 10
num2 = 20
num3 = num1 + num2
Print(num3)

[Link] Oo (Lecturer)
10
Operators Precedence

▪ High precedence means that operator will be calculated first.


▪ */%
▪ +-
▪ When two operators share the same precedence order.
▪ For instance, plus and minus, calculate the expression with left-to-
right calculation

11
[Link] Oo (Lecturer)
Expression

x = 5 + 2 * 3
y = 100 * 20 - 5 / 100 + 0.05

[Link] Oo (Lecturer)
12
Operator precedence exercise

▪ The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same?


▪ ((((13+5)*2)-4)/2)-13
▪ result = 3 + 2 * 2 ** 2 / 2 - 1

[Link] Oo (Lecturer)
13
Exercises
w = 12 % 4
print(w)
x = 10 % 7
print(x)
y = x % (w + 1)
print(y)
z = 5 % 2
print(z)

[Link] Oo (Lecturer)
14
Exercises
a = 10
b = 5
c = 2

result = a + b * c ** 2 - (a // b) + c
result = a + b // c * a - c

[Link] Oo (Lecturer)
15
Compound assignment operator

▪ These are “shortcut” operators that combine a


▪ mathematic operator with the assignment operator (=). For
example, this expression below
a= a+b
a+=b

▪ += -= *= /=

[Link] Oo (Lecturer)
16
Compound assignment operator

animalsOnZoo = 0
numberOfMonkey = 4
animalsOnZoo += numberOfMonkey
numberOfElephants = 2
animalsOnZoo += numberOfElephants
numberOfTiger = 8
animalsOnZoo += numberOfTiger

17
[Link] Oo (Lecturer)

You might also like