Python

Arithmetic in Python V3 || Python Tutorial || Learn Python Programming



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…

Similar Posts

25 thoughts on “Arithmetic in Python V3 || Python Tutorial || Learn Python Programming
  1. It's official! The Socratica Python Kickstarter was a success! Thank you to all of our supporters. Because of you, many more Python videos coming soon!! ๐Ÿ’œ๐Ÿฆ‰

  2. Another "interesting" difference between python 2 and 3:
    python3: (2+2j)//2 -> TypeError: can't take floor of complex number.
    python2: (2+2j)//2 -> (1+0j) # seems like they only truncated the real part

  3. MY 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

  4. At 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))

  5. Small 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.

  6. Arithmetic in Python V3

    Hello, 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

Leave a Reply

Your email address will not be published. Required fields are marked *