0% found this document useful (0 votes)
13 views5 pages

Operators - 1 - Jupyter Notebook

The document discusses different types of operators in Python including assignment, arithmetic, comparison, logical, and membership operators. It provides examples of using each type of operator and the expected output.
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)
13 views5 pages

Operators - 1 - Jupyter Notebook

The document discusses different types of operators in Python including assignment, arithmetic, comparison, logical, and membership operators. It provides examples of using each type of operator and the expected output.
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/ 5

5/31/23, 4:59 AM operators_1 - Jupyter Notebook

Operators:
An operator is a special symbol upon which we perform some
operations on variables and values.

Assignment Operators:
Assignment operators are used to assign values to variables:

In [2]: x = 5
print(x)

In [7]: x = 5
x+=10
print(x)

15

In [8]: y = 10
y%=2
print(y)

localhost:8888/notebooks/Desktop/New folder/operators_1.ipynb 1/5


5/31/23, 4:59 AM operators_1 - Jupyter Notebook

Arithmetic Operators:
Arithmetic operators are used with numeric values to perform common m
athematical operations:

In [9]: a = 10
b = 5
print(a/b)

2.0

In [10]: a = 10
b = 5
print(a//b)

In [11]: a = 10
b = 5
print(a**b)

100000

In [12]: a = 10
b = 5
print(a%b)

localhost:8888/notebooks/Desktop/New folder/operators_1.ipynb 2/5


5/31/23, 4:59 AM operators_1 - Jupyter Notebook

Comparison Operators:
Comparison operators are used to compare two values and returns a boo
lean value:

In [13]: a = 10
b = 12
print(a>b)

False

In [14]: a = 10
b = 12
print(a==b)

False

In [15]: a = 10
b = 10
print(a==b)

True

In [16]: a = 10
b = 12
print(a!=b)

True

Logical Operators:
logical operators are used to combine conditional statements:

localhost:8888/notebooks/Desktop/New folder/operators_1.ipynb 3/5


5/31/23, 4:59 AM operators_1 - Jupyter Notebook

In [17]: print((5>4)and(6<7))

True

In [18]: print((5>4)or(5!=5))

True

In [19]: print(not(5>5))

True

Membership Operators:
in : True if var is the sequence.
False if var is not in the sequence

not in : True if var is not in the sequence.


False if var is in the sequence

Syntax : var in sequence

In [20]: 'a' in 'astronaut'

Out[20]: True

In [21]: 'h' in 'astronaut'

Out[21]: False

In [22]: 'a' not in 'astronaut'

Out[22]: False

In [23]: 'w' not in 'astronaut'

Out[23]: True

localhost:8888/notebooks/Desktop/New folder/operators_1.ipynb 4/5


5/31/23, 4:59 AM operators_1 - Jupyter Notebook

In [ ]: ​

localhost:8888/notebooks/Desktop/New folder/operators_1.ipynb 5/5

You might also like