0% found this document useful (0 votes)
3 views

3 Basic Python Operators

This document provides an overview of basic operators in Python, including arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators. It outlines objectives for understanding these operators and includes learning activities such as reading, journaling, and group discussions. Additionally, it lists various resources and revision questions to reinforce the concepts discussed.

Uploaded by

Ianbrown Wekesa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

3 Basic Python Operators

This document provides an overview of basic operators in Python, including arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators. It outlines objectives for understanding these operators and includes learning activities such as reading, journaling, and group discussions. Additionally, it lists various resources and revision questions to reinforce the concepts discussed.

Uploaded by

Ianbrown Wekesa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

TOPIC 5 : Basic Operators in Python

Introduction.
Operators are the constructs which can manipulate the value of operands. Consider the expression
4 + 5 = 9. Here, 4 and 5 are called operands and + is called operator. Operators are used to perform
operations on variables and values. Operators are used to perform operations on values and
variables. Operators can manipulate individual items and returns a result. The data items are
referred as operands or arguments. Operators are either represented by keywords or special
characters.
Objectives
Objectives by the end of this topic you should be able to describe:

• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators

Learning activities
Learning Activity 5.1: Reading
Read further on Bitwise operators.
Learning Activity 5.2: Journal
Summarize the usage of operators from python documentation.
Learning Activity 5.3: Discussion
In groups of three write programs to demonstrate usage od python operators.
Assessment

Topic resources
1. The Python Tutorial¶. (n.d.). Retrieved from https://docs.python.org/3/tutorial/index.html
2. Mueller, J. P. (n.d.). Beginning Programming with Python For Dummies. S.l.: For
Dummies.
3. (n.d.). Python 3.7.4 documentation. Retrieved from https://docs.python.org/3
4. (n.d.). Git Handbook. Retrieved from https://guides.github.com/introduction/git-
handbook/
5. Shaw, Z. (2017). Learn Python 3 the hard way: a very simple introduction to the
terrifyingly beautiful world of computers and code. Boston: Addison-Wesley.
6. Bader, D. (2018). Python tricks: the book. Vancouver, BC: Dan Bader.
7. Downey, A. B. (2015). Think Python. Sebastopol: OReilly.
8. Ramalho, L. (2016). Fluent Python:Beijing: OReilly.

URL Links
https://www.w3schools.com/python/python_operators.asp
https://docs.python.org/3.4/library/operator.html
https://www.tutorialspoint.com/python/python_basic_operators.htm

TOPIC 5 NOTES
1. Arithmetic operators: Arithmetic operators are used to perform mathematical operations
like addition, subtraction, multiplication and division.
Output:
13
5
36
2.25
2
1

2. Relational Operators: Relational operators compares the values. It either


returns True or False according to the condition.
Output:
False
True
False
True
False
True
3. Logical operators: Logical operators perform Logical AND, Logical OR and Logical
NOT operations.

Output:
False
True
False
Bitwise operators: Bitwise operators acts on bits and performs bit by bit operation.
Output:
0
14
-11
14
2
40
4. Assignment operators: Assignment operators are used to assign values to the variables.
5. Special operators: There are some special type of operators like-
• Identity operators-
is and is not are the identity operators both are used to check if two values are located on
the same part of the memory. Two variables that are equal does not imply that they are
identical.

is True if the operands are identical


is not True if the operands are not identical
Output:
False
True
False
• Membership operators-
in and not in are the membership operators; used to test whether a value or variable is in a
sequence.

in True if value is found in the sequence


not in True if value is not found in the sequence

Output:
True
True
False
True
False
Revision questions
1. What is the output of the following code : print(9//2)
2. What is the answer of this expression, 22 % 3 is?
3. (T/F) x = 8, print(x > 3 or x < 20)
4. Which function overloads the >> operator?
(A) more()
(B) gt()
(C) ge()
(D) None of the above

5. Which operator is overloaded by the or() function?


(A) ||
(B) |
(C) //
(D) /
6. What is the output of the following program :
i=0
while i < 3:
print i
i++
print i+1
(A) 0 2 1 3 2 4
(B) 0 1 2 3 4 5
(C) Error
(D) 1 0 2 4 3 5

You might also like