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

02 Basic Operators

The document discusses different types of operators in Python including arithmetic, relational, and logical operators. It provides examples of common operators like addition, subtraction, comparison operators greater than and less than, AND, OR, and NOT logical operators. It also introduces the input() function in Python to take user input and the int() and float() functions to convert string inputs to numeric types that can be used in calculations or comparisons.

Uploaded by

tamanranya234
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)
22 views

02 Basic Operators

The document discusses different types of operators in Python including arithmetic, relational, and logical operators. It provides examples of common operators like addition, subtraction, comparison operators greater than and less than, AND, OR, and NOT logical operators. It also introduces the input() function in Python to take user input and the int() and float() functions to convert string inputs to numeric types that can be used in calculations or comparisons.

Uploaded by

tamanranya234
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/ 4

5/3/2023

Assist. Lecturer: Hersh Mustafa Hama

[email protected]

Spring Semester 2023

Basic Operators
 Operators are special symbols that carry out arithmetic or logical computation.
 The value that the operator operates on is called the operand.
 Arithmetic Operators: Arithmetic operators are used to perform mathematical
operations like addition, subtraction, multiplication, etc.
 Addition (+): Add two operands. (e.g. x + y)
 Subtraction (-): Subtract right operand from the left. (e.g. x – y - 2)
 Multiplication (*): Multiply two operands. (e.g. x * y)
 Division (÷): Divide left operand by the right one. (e.g. x / y)
 Modulus (%): remainder of the division of left operand by the right. (x % y)
 Exponent (**): left operand raised to the power of right. (e.g. x**2) 2

1
5/3/2023

Arithmetic Operation: Example

OUTPUT

Relational (Comparison) Operators


 Comparison operators are used to compare values.
 It returns either True or False according to the condition.
 Greater than (>): True if left operand is greater than the right. (e.g. x > y)
 Greater than or equal to (>=): True if left operand is greater than or equal to
the right. (e.g. var1 >= var2)
 Less than (<): True if left operand is less than the right. (e.g. var1 < var2)
 Less than or equal to (<=): True if left operand is less than or equal to the
right. (e.g. var1 <= var2)
 Equal to (==): True if both operands are equal. (e.g. var1 == var2)
 Not equal to (!=): True if operands are not equal (e.g. var1 != var2) 4

2
5/3/2023

Comparison Operators: Example

OUTPUT

Logical Operators
 Logical operators are:
 AND: True if both the operands are true.
 OR: True if either of the operands is true.
 NOT: True if operand is false (complements the operand) true.

3
5/3/2023

Input Function
 To allow flexibility, we might want to take the input from the user. In Python, we
have the input() function to allow this.

 Here, we can see that the entered value 20 is a string, not a number.
 To convert this into a number we can use int() or float() functions.

 This same operation can be performed using the eval() function.


 It can evaluate even expressions, provided the input is a string.

You might also like