0% found this document useful (0 votes)
13 views14 pages

Operators in Python

Operators in python

Uploaded by

Rowen Fernando
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
13 views14 pages

Operators in Python

Operators in python

Uploaded by

Rowen Fernando
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

UNIT1 - Programming

Week [05] – Python – Part I

1
Lesson Learning Outcome
Pass Merit Distinction

LO3 Implement basic algorithms in code using an


Integrated Development Environment (IDE)

P3 Write a program that M3 Use the IDE to manage D3 Evaluate the use of an
implements an algorithm the development process of IDE for development of
using an IDE. the program. applications in contrasted
with not using an IDE.

2
Python Language

▪ Python is interpreted: Python is processed at runtime by the


interpreter. You do not need to compile your program before executing
it.
▪ Python is Interactive: You can actually sit at a Python prompt and
interact with the interpreter directly to write your programs.
▪ Python is Object-Oriented: Python supports Object-Oriented style
▪ Python is a Beginner's Language: Python is a great language for
beginners & supports the from simple text processing to WWW
browsers to games.

3
Features of Python

▪ Easy-to-learn, Easy-to-read, Easy-to-maintain:

▪ A broad standard library: Python's bulk of the library is very portable

▪ Portable: Python can run on a wide variety of hardware platforms

▪ Extendable: You can add low-level modules to the Python interpreter.

▪ Databases: Python provides interfaces to all major commercial databases.

▪ GUI Programming: Python supports GUI applications

▪ Scalable: Has a better structure and support for large programs than shell scripting.

4
Basic rules in Python

▪ Language is Case Sensitive ( Capitals & Simples are different )

▪ All command are in lower case

▪ Code blocks are identified by Indentation

▪ Editor is language sensitive

▪ Commands appear in - Red

▪ Functions appear in - Purple

▪ Strings appear in - Green

5
Assigning Values to Variables

▪ Python variables do not have to be explicitly declared to reserve memory space.


▪ The declaration happens automatically when you assign a value to a variable.
▪ The equal sign (=) is used to assign values to variables.

6
Standard Data Types

Python has five standard data types:

▪ Number – Can store integers and fractional numbers

▪ String – Can store a series of characters

▪ List – Can store array of objects ( any kind )

▪ Tuple – Same as list but objects cannot be changed

▪ Dictionary – List of (key + value) pairs

7
Operators & Operands

Expression → 4+5 is equal to 9.


Here 4 and 5 are called operands and + is called operator.
Python language supports following type of operators.

▪ Arithmetic Operators
▪ Comparison Operators
▪ Logical (or Relational) Operators
▪ Assignment Operators
▪ Conditional (or Ternary) Operators

8
Arithmetic Operators
Assume,

Variable a holds 10

Variable b holds 20

9
Comparison Operators
Assume,
variable a holds 10
variable b holds 20

10
Assignment Operators

11
Operator Precedence
▪ Operator precedence
refers to the priority of
operators.
▪ That is the order in which
they are evaluated.

12
Operator Example 1
Operator Example 1
x=10
y=3 OUIPUT
print("x =",x) x = 10
print("y =",y) y = 3
print("x + y =",x+y) x + y = 13
print("x - y =",x-y) x - y = 7
print("x * y =",x*y) x * y = 30
print("x / y =",x/y) x / y = 3.3333333333333335
print("x % y =",x%y) x % y = 1
print("x // y =",x//y) x // y = 3
print("x ** y =",x**y) x ** y = 1000

x += y
print("After x+=y, now x =",x) After x+=y, now x = 13

13
Lesson Summary

▪ Features of Python
▪ Variables & Assignment
▪ Operators & Operands
▪ Arithmetic Operators
▪ Comparison Operators
▪ Assignment Operators
▪ Operator Precedence

14

You might also like