Today we talk about the rules of arithmetic in Python Version 3. The key detail is when combining two numbers, Python will widen numbers to make sure they are all of the same type. (In Python v3, there are three numeric types: ints, floats and complex numbers.) And division has changed from version 2. Now, division always returns the correct math value as a float. It no longer returns the quotient when you divide two whole numbers.

And beware of division by 0!

➢➢➢➢➢➢➢➢➢➢

We recommend:

Python Cookbook, Third edition from O’Reilly

The Mythical Man Month – Essays on Software Engineering & Project Management

Shop Amazon Used Textbooks – Save up to 90%

➢➢➢➢➢➢➢➢➢➢

Subscribe to Socratica:

To support more videos from Socratica, visit

Socratica Patreon

Socratica Paypal

We also accept Bitcoin! 🙂

Our address is: 1EttYyGwJmpy9bLY2UcmEqMJuBfaZ1HdG9

➢➢➢➢➢➢➢➢➢➢

Python instructor: Ulka Simone Mohanty

Written & Produced by Michael Harrison

FX by Andriy Kostyuk

source

Ahmed AhmedJuly 2, 2019 at 8:20 pmi love you, you oped to me new world thanxxx

1 conscience 0 dimensionJuly 2, 2019 at 8:20 pmwe have to raise an exception

Ghaz TJuly 2, 2019 at 8:20 pmAppreciate the effort you guys put in 🙂

Krishnendu BhattacharjeeJuly 2, 2019 at 8:20 pmwhen int is used with a float number, the fractional part gets removed, THEY ARE NOT ROUNDED OFF, AS MENTIONED IN THE VIDEO…

Az0ddJuly 2, 2019 at 8:20 pmRIP long

T DJJuly 2, 2019 at 8:20 pmThese videos should have more views, they are so professional…

Kiran ShahJuly 2, 2019 at 8:20 pmYour python tutorials are awesome !!!

It will be better if you will share the slides for this playlist ….Please …

Thanks in advance

David JamriskaJuly 2, 2019 at 8:20 pmThis makes me want to watch Stargate..

great videos

ALGORITHM KIDJuly 2, 2019 at 8:20 pmMY question is why we cant convert complex numbers into floats ? like DUh just add -0j in the complex number you will get the float back simple logic. pls reply

arindom dasJuly 2, 2019 at 8:20 pmHow to clear the window with out using quit()

王玮July 2, 2019 at 8:20 pmLove this channel!

AuzirkJuly 2, 2019 at 8:20 pmWho tf disliked this video lmao??

Fernando SuyamaJuly 2, 2019 at 8:20 pmAwesome videos! You can add exponent operator **, for example: 4**2 = 16

wolfedog99July 2, 2019 at 8:20 pmAt 1:10 it is stated that the float is rounded then made into an int. This is incorrect, the float is truncated then made into an int, as such using int() to convert 3.2 or 3.8 will return 3 and -3.2 or -3.8 will return -3. Which is consistent with normal integer arithmetic.

To round and convert you must use round()[yields 3, 4, -3,- 4],

for more control import "math" and use math.ceil()[yields 4 ,4, -3, -3] or math.floor() [yields 3, 3, -4, -4]

Also to get [4, 4, -4, -4] using the above inputs: int(math.copysign(math.ceil(abs(g)), g))

Tommy KellyJuly 2, 2019 at 8:20 pmI'm impressed how clear you made this topic.

yvrelnaJuly 2, 2019 at 8:20 pmSmall suggestion: the terminology narrower and wider is, in my opinion, a bit of a misnomer, because Python allows arbitrary sized integers but only allows fixed size for floats and complex numbers. This means that in some sense integers are wider than floats and complex numbers.

SocraticaJuly 2, 2019 at 8:20 pmArithmetic in Python V3Hello, hello! Our latest Python tutorial is on arithmetic in Python V3. The main difference between V2 and V3 is that whole number division in V3 returns the correct value as a float, while in V2 it returns the quotient.

More videos are coming soon!

#LearnMore