Operators in python | Python3.9 | Python tutorial in Hindi for absolute beginners
Artithmetic Operators
You will probably already be familiar with these, since they come from basic mathematics.
The arithmetic operators are addition (+), subtraction (-), multiplication (*), division (/), exponent (**), floor division (//) and modulus (%). The first four are fairly simple; they are addition, subtraction, multiplication and division, and you will probably already be familiar with them.
Assignment Operators
If you have some programming experience, you will certainly have used assignment operators before. They assign a certain value to a variable. The most used one is =. To use it, simply type the name of the variable you want to assign a new value to, the =, and the value you want to be assigned.
Operators in Python
This tutorial covers the different types of operators in Python, operator overloading, precedence and associativity.
Just like in mathematics, programming languages like Python have operators. You can think of them as extremely simple functions that lie at the basis of computer science. These are the simplest operations to which a computer program can be reduced. They are essential knowledge for any aspiring Data Scientist or Software Engineer.
In this tutorial, you will learn about
The different types of operators: Arithmetic, Assignment, Comparison and Logical
Operator Overloading
Precedence
Associativity
If you would like to learn more about the basics of the Python Programming Language, make sure to check out our free Intro to Python for Data Science course.
Artithmetic Operators
You will probably already be familiar with these, since they come from basic mathematics.
The arithmetic operators are addition (+), subtraction (-), multiplication (*), division (/), exponent (**), floor division (//) and modulus (%). The first four are fairly simple; they are addition, subtraction, multiplication and division, and you will probably already be familiar with them.
Addition
print(5 + 2)
Subtraction
print(5 - 2)
Multiplication
print(5 * 2)
Division
print(5 / 2)
7
3
10
2.5
The other three are a bit more complicated. The exponent operator means 'raised to the power of'. For example, 2 ** 3 means that 2 is multiplied with itself 3 times, so 2 ** 3 is the same as 2 * 2 * 2, which is equal to 8.
Floor division is the same as normal division, except that the result is always rounded off to the bottom. In the example below, 5 is divided by 2, resulting in 2.5. But since it's the floor division, 2.5 is rounded off to 2.
Finally, the modulus is the remainder after division. In the case of 5%2, the number 2 only fits twice in 5, which means that the remained is 1.
Exponent
print(5 ** 2)
This is the same as 5 * 5
Floor Division
print(5 // 2)
Modulus
print(5 % 2)
25
2
1
In Python, the addition operator can also be used to concatenate strings. This means that they will be assembled into a single string, for example:
firstName = "Théo"
introduction = "Hi, my name is " + firstName + "."
print(introduction)
Hi, my name is Théo.
Assignment Operators
If you have some programming experience, you will certainly have used assignment operators before. They assign a certain value to a variable. The most used one is =. To use it, simply type the name of the variable you want to assign a new value to, the =, and the value you want to be assigned. For example, if you want to assign the value 100 to the variable balance, you can do the following:
balance = 100
print(balance)
100
If you want to increment the value of balance with 10, you can use balance += 10. This is the equivalent of balance = balance + 10, but it's much shorter.
balance += 10
print(balance)
110
The same holds for -=, balance -= 10 is the same as balance = balance - 10:
print(balance)
balance -= 10
print(balance)
110
100
The other assignment operators work in exactly the same way. These are:
*=
/=
**=
//=
%=
C
On this page of the site you can watch the video online Operators in python | Python3.9 | Python tutorial in Hindi for absolute beginners with a duration of hours minute second in good quality, which was uploaded by the user CodeWithRajat 14 March 2021, share the link with friends and acquaintances, this video has already been watched 9 times on youtube and it was liked by 1 viewers. Enjoy your viewing!