Day 4: Python Operators

Some basic operators include

+, -, *, /, %, >, >=, <, <=, ==, !=, and, not, or, is, in, =, +=, -=, *=, /=, ** 
>>> 1+1
2
>>> 1+2.3456
3.3456
>>> 45-643
-598
>>> 98.34-334
-235.66
>>> 3.2*10
32.0
>>> 32*10
320
>>> 32/10
3.2
>>> 32/16
2.0
>>> type(12-5)
<class 'int'>
>>> type(12/6)
<class 'float'>
>>> 12/2
6.0
>>> 5 - 1.0
4.0

Point to note: If any operand is a float, the result will return in float.

Point to note: Dividing numbers also returns float.

Booleans

>>> 34>4
True
>>> 34<4
False
>>> 10 != 10
False

Operator precedence

>>> 3*4 -10
2
>>> 3*(4-10)
-18

Some more operators in Python

// - Integer division
** - Exponent
% - Modulo

Some examples

>>> 4**5
1024
>>> 10%2
0
>>> 45%8
5
>>> 20/9
2.2222222222222223
>>> 20//9
2
>>> 10//-5
-2
>>> 10//-3
-4
>>> 10//3
3
>>>

That concludes for today!

What’s your Reaction?
+1
0
+1
0
+1
0

Published by Soumil Roy

I'm a Full-Stack Developer with 7+ years of experience in Web design & development .Currently building expertise in React, TypeScript & GraphQL

Leave a comment

Your email address will not be published.

Open WhatApp
Hello 👋 Click the button below connect with me.