0% found this document useful (0 votes)
39 views8 pages

PYthon Class 8 Telugu

The document discusses various types of operators in Python including arithmetic, relational, logical, bitwise and assignment operators. It provides examples of using each operator type and notes on string and boolean operator behavior.

Uploaded by

THE KING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views8 pages

PYthon Class 8 Telugu

The document discusses various types of operators in Python including arithmetic, relational, logical, bitwise and assignment operators. It provides examples of using each operator type and notes on string and boolean operator behavior.

Uploaded by

THE KING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Python Operators

====================

Operator
~~~~~~~~~~~~~

Operator is used to operate the operands

Operand
~~~~~~~~~~~

Operand is operated by the operator

eg:
a+b

here a and b are Operands


+ is the operator

In Python Programming there are different types of operators such as follows:

Arithmetic Operators
~~~~~~~~~~~~~~~~~~~~~~~~~

>>> a=10
>>> b=20
>>> c=a+b
>>> c
30
>>>
>>> c=a-b
>>> print(c)
-10
>>>
>>> c=a*b
>>> print(c)
200
>>>
>>> c=b/a
>>> print(c)
2.0
>>>
>>>
>>>
>>> a=25
>>> b=3
>>>
>>> c=a/b
>>> print(c)
8.333333333333334
>>>
>>>
>>> c=a%b
>>> print(c)
1
>>>
>>>
>>>
>>> c=a//b
>>> print(c)
8
>>>
>>>
>>>
>>> a=2
>>> b=3
>>>
>>> c=a**b
>>> print(c)
8
>>>

eg:

# Program to perform (a+b)^2

a=int(input("Enter A Value:"))
b=int(input("Enter B Value:"))
c=(a+b)**3
print("(a+b)^3 =",c)

eg:

# Program to display your Name for N Number of times


nm=input("Enter Your Name:")
n=int(input("Enter How many times do you want to display:"))
print(nm*n)

Chaining Operators
----------------------

>>> a=b=c=d=e=10
>>> print(a)
10
>>> print(b)
10
>>> print(c)
10
>>> print(d)
10
>>> print(e)
10
>>>
>>>
>>> a,b,c,d=10,20,30,40

Note:
~~~~~~~~~

We can use *,+ operators for str type also

+ operator is used to joining of two strings


eg:

# Program to perform + on str types


nm=input("Enter Your Name:")
age=input("Enter Your Age:")
print("My Name is :",nm," and my age is :",age)
print(nm+age)

If we use * for str type then compulsory one argument must be int and another
argument must be of int type

eg:

# Program to perform * operator on strings


s=input("Enter Any String:")
n=int(input("Enter Any Value:"))
print(s*n)

1. = --> Assignment eg: a=10


2. == --> Comparison eg: a==10

Note:
~~~~~~~~~~~

Relational operators are also applicable to strings

>>> a='edusaa'
>>> b='edusaa'
>>>
>>> print(a>b)
False
>>>
>>>
>>> print(a<b)
False

>>> print(a>=b)
True

>>> print(a<=b)
True
>>>
>>>
>>> print(a==b)
True

The relational operators are also applicable to boolean types i.e, True or
False

eg:
>>> print(True+True)
2
>>>
>>>
>>>
>>> print(True>False)
True

>>>
>>>
>>> print(True<False)
False
>>>
>>>
>>> print(True>=False)
True
>>>
>>>
>>> print(True<=False)
False
>>>
>>>
>>> print(10>True)
True
>>>
>>>
>>>
>>> print(True<10)
True
>>>
>>>
>>> print(10.5>5.5)
True
>>>
>>>
>>> print(10.5>True)
True
>>>
>>> print(10.5>True>False)
True
>>>
>>>
>>>
>>>

Logical Operators
----------------------

for Boolean Types


~~~~~~~~~~~~~~~~~~~~~

>>> True and True


True
>>>
>>>
>>> True and False
False

>>> False and True


False
>>>
>>>
>>> False and False
False
>>>
>>>
>>> True or True
True
>>>
>>> True or False
True

>>> False or True


True
>>>
>>>
>>> False or False
False
>>>
>>>
>>>
>>>
>>> not True
False
>>>
>>>
>>> not False
True
>>>
>>>

For Non Boolean Types


~~~~~~~~~~~~~~~~~~~~~~~~~~~

x and y
~~~~~~~~~~~~

If first argument(x) is zero then result is zero otherwise result is second


argument(y)

eg:
>>> 10 and 100
100
>>>
>>>
>>> 0 and 10
0
>>>
>>>

x or y
~~~~~~~~~~~~~~

If first argument(x) is Non-zero then result is Non-zero otherwise result is


second argument(y)

eg:

>>> 10 or 100
10
>>>
>>>
>>> 100 or 10
100
>>>
>>> 0 or 10
10
>>>
>>>
>>> 10 or 0
10
>>>
>>>
>>> 0 or 100
100
>>>

Not x
==========

If x is evaluates to False then the result is True otherwise False

eg:

>>> not 100


False
>>>
>>>
>>>
>>> not 0
True
>>>
>>>
>>> "edusaa" and "edusaa youtube channel"
'edusaa youtube channel'
>>>
>>>
>>> '' and "edusaa"
''
>>>
>>> "edusaa" or ""
'edusaa'
>>>
>>> "" or "edusaa"
'edusaa'
>>>
>>>
>>> not ""
True
>>>
>>>
>>> not "edusaa"
False
>>>
>>>

Bitwise Operators
====================

We can apply these operators on bitwise

These are applicable on int and boolean types only

eg:

>>> print(100&200)
64
>>>
>>> print(100.5&200.5)
Traceback (most recent call last):
File "<pyshell#222>", line 1, in <module>
print(100.5&200.5)
TypeError: unsupported operand type(s) for &: 'float' and 'float'
>>>
>>>
>>> print(True&False)
False
>>>
>>>

& --> If both bits are 1 then the result is 1 otherwise 0

| --> If atleast one bit is 1 then result is 1 otherwise 0

^ --> If bits are different then only result is 1 otherwise 0

1--> 0
0 --> 1

<< --> Bitwise Left Shift

>> --> Bitwise Right Shift

You might also like