0% found this document useful (0 votes)
15 views6 pages

Unit7 Read Me

The document discusses Python programming including its features, operators, variables, user input functions, and conditional statements. Python is an open source, object-oriented programming language. It covers arithmetic, assignment, relational, and logical operators as well as if, if-else, and if-elif conditional statements.

Uploaded by

Kaung Khant Kyaw
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)
15 views6 pages

Unit7 Read Me

The document discusses Python programming including its features, operators, variables, user input functions, and conditional statements. Python is an open source, object-oriented programming language. It covers arithmetic, assignment, relational, and logical operators as well as if, if-else, and if-elif conditional statements.

Uploaded by

Kaung Khant Kyaw
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
You are on page 1/ 6

Unit 7

Learning objectives

 Features of Python
 Writing and executing commands in Python
 How to exit the Python Shell
 Operators in Python
 Variation in Python
 Using the input() function for user input
 Conditional constructs

Snap Recap

1. What do you understand by programming?


Writing codes or comprehending languages into something that computer can understand to
create programs
2. Why do you need programming language?
To create programs

What is Python?
A high-level programming language which is open source and object-oriented. (OOP- Object-
oriented program)

Python owner
Python Software Foundation (PSF)

Usage of Python
 To create web-based applications
 To handle large amounts of data
 To perform complex calculations
 To connect database systems and to read and modify files
Features of Python
 Python source code is freely available.
 It is a loosely typed object-oriented programming language with few keywords and simple
English-like structure, and therefore easy to learn.
 It supports Graphical User Interface (GUI).

IDLE: INTEGRATED DEVELOPMENT LEARNING ENVIRONMENT—EDIT, RUN, BROWSE, AND DEBUG

How to exit the Python Shell

Type quit (), or exit ()

Operators in Python
Arithmetic operators

Operator Name Syntax Example


+ Addition x+y >>>5+4
9
- Subtraction x-y >>>5-4
1
* Multiplication x*y >>>3*6
18
/ Division x/y >>>8/2
4
% Modulus x%y >>>5%2
1
** Exponentiation x**y >>>5**3
125
// Floor division x//y >>>15//4
3

Assignment operators
Operator Syntax Description Example
= Num=5 Assigning >>>Num=5
+= Num+=5 Increase the value of Num=17>>>
OR Num by 5 Num+=5
Num=Num+5 22
-= Num-=5 Decrease the value of Num=20
OR Num by 5 >>>Num-=5
Num=Num-5 15
*= Num*=5 Multiplies the value of Num=20
OR Num by 5 >>>Num*=5
Num=Num*5 100
/= Num/=5 Divides the value of Num=100
OR Num by 5 >>>Num/=5
Num=Num/5 20
%= Num%=5 Displays the remainder Num=25
OR by dividing the value of >>>Num%3
Num=Num%5 Num by 5 1
//= Num//=5 Variable Num is Num=35
OR assigned floor value of >>>Num//3
Num=Num//5 division of Num by 5 11
**= Num**=5 Num is assigned a Num=10
OR value of last value of >>>Num**=2
Num=Num**5 Num raised to the 100
power of 5

Relational operators

Operator Syntax Description Example


== x==y Equal to x=16;y=20
>>>x==y
False
!= x!=y Not equal to x=15;y=25
>>x!=y
False
> x>y Greater than X=6;y=10
>>x>y
False
< x<y Less than X=10;y=15
>>>x<y
True
>= x>=y Greater than or equal X=13;y=14
to >>>x>=y
False
<= x<=y Less than or equal to X=16;y=15
>>>x<=y
False

Logical operators

Operator Syntax Description Example


and x>5 and x<=10 Returns True if both >>>print (“10<25 and
the conditions are True 5>6:”, 10<25 and 5>6)
False
or Alpha=”A” or Returns True if any one >>>print (“10<25 or
Alpha=”a” of the conditions is 5>6:”, 10<25 or 5>6)
True True
not Not (Num%10==0) Reverses the result, >>>print (“not 35<60”,
returns False if the not 35<60)
result is True False

Variable in Python

Variable: named memory locations whose value may chance during the execution of the program. Rules
for naming:

 Can consist of letters, digits, and underscore (_)


 Can start with a letter or an underscore (_)
 Cannot have space
 Keywords are not allowed
 Case-sensitive

Declaring variables

- Example: x = 5
Assign multiple values to multiple variables

X, y, z= 15, 18.5, “hello”

Assigning the same value to multiple variables

x= y= z= 25

Using input () function for user input

Syntax: input(<Prompt>)

Conditional constructs

- If statement
- If- else statement
- If- elif ladder

If statement

The if statement checks if the condition given after if is true, then the statement (s) following
the if condition is/ are executed. If condition is false, then the flow of control is transferred to
the next un-indented statement (s).

Syntax: if <condition>:
Statement (s)

Rules for using if condition

 Must end with a colon (:)


 Statement within the ‘if’ that need to be executed if the conditions if true should be indented,
otherwise the control skip the block of statements inside it.
 The if condition can also be written in parenthesis () but it is not mandatory.
 There is no limit to the number of statements that can appear under an if block

If-else statement

Syntax: if <condition>:

Statement (s)

else:

Statement (s)

If-elif statement

Syntax:

If <condition>:

Statement (s)

Elif<condition>:

Statement (s)

Elif<condition>:

Statement (s)

Else:

Statement (s)

You might also like