×
STUDY HARD SO YOU CAN LIVE YOUR LIFE AS YOU WANT.
--Your friends at LectureNotes

Note for Python Programming - PY By ganesh kavhar

• Python Programming - PY
• Note
• Computer Science Engineering
• 147 Views
• Uploaded 8 months ago
0 User(s)

Text from page-1

Basic Operators in Python 1. Arithmetic operators: Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication and division. OPERATOR DESCRIPTION SYNTAX + Addition: adds two operands x+y - Subtraction: subtracts two operands x-y * Multiplication: multiplies two operands x*y / Division (float): divides the first operand by the second x/y // Division (floor): divides the first operand by the second x // y Modulus: returns the remainder when first operand is divided x% by the second y % filter_none edit play_arrow brightness_4 # Examples of Arithmetic Operator a =9 b =4 # Addition of numbers add = a + b # Subtraction of numbers sub = a - b # Multiplication of number mul = a * b # Division(float) of number div1 = a / b # Division(floor) of number div2 = a // b # Modulo of both number mod = a % b

Text from page-2

# print results print(add) print(sub) print(mul) print(div1) print(div2) print(mod) 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. OPERATOR DESCRIPTION SYNTAX > Greater than: True if left operand is greater than the right x>y < Less than: True if left operand is less than the right x<y x == == Equal to: True if both operands are equal y != Not equal to - True if operands are not equal x != y Greater than or equal to: True if left operand is greater than or x >= >= equal to the right y <= Less than or equal to: True if left operand is less than or equal x <=

Text from page-3

to the right y filter_none edit play_arrow brightness_4 # Examples of Relational Operators a = 13 b = 33 # a > b is False print(a > b) # a < b is True print(a < b) # a == b is False print(a == b) # a != b is True print(a != b) # a >= b is False print(a >= b) # a <= b is True print(a <= b) Output: False True False True False True 3. Logical operators: Logical operators perform Logical AND, Logical OR andLogical NOT operations. OPERATOR DESCRIPTION SYNTAX

Text from page-4

and Logical AND: True if both the operands are true x and y or Logical OR: True if either of the operands is true x or y not Logical NOT: True if operand is false not x filter_none edit play_arrow brightness_4 # Examples of Logical Operator a = True b = False # Print a and b is False print(a and b) # Print a or b is True print(a or b) # Print not a is False print(not a) Output: False True False 4. Bitwise operators: Bitwise operators acts on bits and performs bit by bit operation. OPERATOR DESCRIPTION SYNTAX & Bitwise AND x&y | Bitwise OR x|y ~ Bitwise NOT ~x