What are operators in Python

Why do we use operators in Python? For one reason of course. To perform various kinds of operations on variables.

Arithmetic operations like addition, subtraction, multiplication or division are nothing new to us. Right? 

As a result, we know how to use those operators.

However, a programming language needs a lot more than that. 


If you are a complete beginner your journey to learn TensorFlow might start from here.

For the TensorFlow beginners we have a dedicated category – TensorFlow for Beginners.

But besides that, you may need to learn several other machine learning and data science libraries.

As a result, you may check these categories as well – NumPy, Pandas, Matplotlib.

However, without learning Python, you cannot learn the usages of these libraries. Why? Because they all use Python as the Programming language.

Therefore please learn Python at the very beginning and start learning TensorFlow.

And, finally please check our Mathematics, Discrete Mathematics and Data Structures categories specially. We have tried to discuss from basic to intermediate level so that you can pick up the core ideas of TensorFlow.


Besides arithmetic operations, there are logical operations.

Let’s remember a few golden rules.

Operators in Python or any programming language are basically special symbols. And we know in the computer keyboard where to find them.

Let’s see some examples.

first = 989
second = 456


add = first + second

subtract = first - second

multiply = first * second


division_one = first / second


division_two = first // second


print(add)
print(subtract)
print(multiply)
print(division_one)
print(division_two)

We see that there are two types of divisions. For the first one we have used the ‘/’ symbol.

And for the second, we have used the ‘//’ symbol.

What does that mean?

Let’s see the output. 

That will answer our query.

1445
533
450984
2.168859649122807
2

If we have used the ‘//’ symbol in a division, that will give us a whole number. We call it floored integer.

It ignores the point and the numbers after that.

As an outcome, we get our output as 2.

There are two more interesting arithmetic operators. 

Let’s see the example first.

modulo = first % second

power = first ** second

print(modulo)
print(power)

The modulo symbol, that is the ‘%’ symbol, gives us the remainder of a division.

On the other hand, the power uses the ‘**’ symbol. 

When we place 456 as the power of the number 989, the output becomes quite large.

However, Python can tackle that.

Let’s see the result.

# output of modulo
77
# output of power
6449246376215082982539402970687909670095325611372845123844127982752274151695898177252955195967945981221813042671899247833442088732791270603746710961016584134191699091171175460450823610547693787350240619455929337082769717292639799800138493003473467337835483542778720479201140517585402308509689224324599692917921079255748677905911359770815574268603001630880294146184321052258410645941057809435219800421873232328816326237270903306466505523369690935347793746334354132618519561361276706943186952046542143393210388932682677795280143207216294608578797800557551680850972251333178463257388525198393233670102575328829089039651799997435226911640253919445290280693754472513055031521248112015531513166700403527209429917619712646215806692193308949051929420240960998906891701945795449575557676872900318012746015994330419915059725078714576671260301220883597816175682631214852187646035976200591604461688433536658615765829206202153902890662294957389906274835284217874380866889622712826869352216415218840046704475459622654322393280359805946664780893093597168871800817930561447915485621007207609942104117952510144618748080893178846131595951031518441169081367527116050155049049745466754489305826763586479446627578186122991557392624656692060138531221078447513491136888470270112415022903958978903116823556380387776106864540882930253473414586754906883238764407881972326766887830304543942561

We have not finished yet. In the next section, we will discuss more on operators.

What Next?

Books at Leanpub

Books in Apress

My books at Amazon

GitHub repository

Flutter, Dart, Python and TensorFlow

C, C++ Java, and Game Development

Twitter


Posted

in

,

by

Comments

One response to “What are operators in Python”

  1. […] the last section we have seen arithmetic operators in Python. However we didn’t discuss Arithmetic Operators Python […]

Leave a Reply