It is for python, you can see here new things

bagga26085 2 views 38 slides Oct 29, 2025
Slide 1
Slide 1 of 38
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38

About This Presentation

For python


Slide Content

UNIVERSITY INSTITUTE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING PYTHON PROGRAMMING ( 24CSP-203 ) Unit No. 1 Chapter No. 1.2 Lecture No. 2 Topic : Operators & Control Structures Academic Session 2025-26 ODD Semester Jul-Dec 2025 Dr. Gitanjali E16525 Assistant Professor

Learning Objectives Apply arithmetic, relational, logical, assignment, bitwise, membership, and identity operators. Understand and implement decision-making constructs: if, if-else, if- elif -else. Use loops effectively (for, while) for repetitive operations. Control loop execution using break, continue, and pass. 1 Dr. Gitanjali E16525 Assistant Professor

Topics Covered Operators in Python Control Structures 2 Dr. Gitanjali E16525 Assistant Professor

Operators in Python In Python, operators are special symbols or keywords that perform operations on variables and values. They are used to perform computations, comparisons, and logical operations. 3 Operators & Control Structures Operators Dr. Gitanjali E16525 Assistant Professor

Operators in Python i) Arithmetic Operators ii) Relational Operators iii) Assignment Operator iv) Logical Operators v) Bitwise Operators vi) Ternary Operator vii) Membership Operators viii) Identity Operators 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

Arithmetic Operators: Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, etc. 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

3 Operators & Control Structures

Logical Operator: Logical operators are used to check whether an expression is True or False. They are used in decision-making. The primary logical operators in Python are and, or, and not. These operators allow you to create complex conditional statements by combining simpler conditions. 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

Bitwise operator: Bitwise operators act on operands as if they were strings of binary digits. They operate bit by bit, hence the name. For example, 2 is 10 in binary, and 7 is 111. 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

3 Operators & Control Structures

Ternary Operator: The ternary operator in Python, also known as the conditional expression, provides a concise way to evaluate a condition and choose between two outcomes. This operator can be written in a single line, making your code shorter and more readable. Syntax: true_value if condition else false_value 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

Membership Operators: In Python, in and not in are the membership operators. They are used to test whether a value or variable is found in a sequence (string, list, tuple, set and dictionary). 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

Identity Operators: Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

What Are Control Structures? Control structures allow you to control the flow of your program based on conditions and repetitions. Python supports: Conditional statements (if, if-else, if- elif -else) Loops (for, while) 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

Conditional Statements : Conditional statements in Python allow you to execute different blocks of code based on whether a specific condition is true or false. 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

Python supports the usual logical conditions from mathematics: Equals: a == b Not Equals: a != b Less than: a < b Less than or equal to: a <= b Greater than: a > b Greater than or equal to: a >= b An "if statement" is written by using the ‘if’ keyword. 3 Operators & Control Structures

if Statement : The if statement is used to execute a block of code only if a condition is true. Syntax: if condition: # code to execute if condition is True 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

if-else Statement : The if-else statement is used when you want to execute one block if the condition is true, and another if it is false. if condition: # code if condition is True else: # code if condition is False 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

if- elif -else Statement : This is used when you need to check multiple conditions. If the first if is False, it checks the elif (else-if). If none are True, it executes the else. if condition1: # code if condition1 is True elif condition2: # code if condition2 is True else: # code if none of the above are True 3 Operators & Control Structures

Loops in Python Loops are used to repeat a block of code multiple times until a certain condition is met. Python provides two main types of loops: for loop – used for iterating over a sequence. while loop – used when the number of iterations is not known in advance. 3 Operators & Control Structures

for Loop The for loop is used to iterate over sequences like lists, strings, ranges, etc. Syntax: for variable in sequence: # block of code 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

while Loop The while loop keeps executing the code as long as the condition is true. Syntax: while condition: # block of code 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

Loop Control Statements in Python These are special statements used to control the behavior of loops. break continue pass 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

break Used to exit the loop immediately, even if the loop condition is still true. 3 Operators & Control Structures BREAK Dr. Gitanjali E16525 Assistant Professor

continue Skips the current iteration and continues with the next. Continue 3 Operators & Control Structures Dr. Gitanjali E16525 Assistant Professor

pass Used as a placeholder for future code. Does nothing when executed. 3 Operators & Control Structures pass Dr. Gitanjali E16525 Assistant Professor

pass Used as a placeholder for future code. Does nothing when executed. 3 Operators & Control Structures pass Dr. Gitanjali E16525 Assistant Professor

Decision-Based Applications Billing and Discounts Loop-Based Reports Input Validation 3 Applications of the Topic Dr. Gitanjali E16525 Assistant Professor

Use different types of operators (arithmetic, relational, logical, etc.) to evaluate expressions. Make decisions using if, if-else, and if- elif -else statements. Implement loops (for, while) to repeat actions. Control the flow of loops using break , continue , and pass statements. 3 Summary of the Topic Dr. Gitanjali E16525 Assistant Professor

Next Lecture 7 Dr. Gitanjali – E16525 Assistant Professor Topic(s) Functions in Python Function syntax, calling, arguments Local vs Global variables

Which of the following is a valid variable name in Python? A. 1value B. value1 C. value-1 D. @value 26 Quiz/ FAQ’s Dr. Gitanjali E16525 Assistant Professor

Which built-in function returns the memory location of a variable? A. loc () B. id() C. mem () D. addr () 27 Quiz/ FAQ’s Dr. Gitanjali E16525 Assistant Professor

What will be the output of type(10.5)? A. <class ' int '> B. <class ' str '> C. <class 'float'> D. <class ' bool '> 28 Quiz/ FAQ’s Dr. Gitanjali E16525 Assistant Professor

R eferences/ Articles/ Videos 29 Dr. Gitanjali E16525 Assistant Professor Suggestive Readings Think Python How to Think Like a Computer Scientist (Allen B. Downey) Fundamentals of Python First Programs, 2nd Edition (Kenneth A. Lambert) Programming and Problem Solving with Python (Ashok Namdev Kamthane , Amit Ashok Kamthane )

Faculty-curated videos, NPTEL, Coursera, LinkedIn, or other relevant learning resources 30 Dr. Gitanjali E16525 Assistant Professor https://www.coursera.org/specializations/python https://www.coursera.org/learn/python-crash-course https://nptel.ac.in/courses/106106182

Class-Wise Feedback 29 Dr. Gitanjali – E16525 Assistant Professor

Thank You 32