Programming, Python

6 Interesting Facts You Are Less Familiar with Python Int Data Type

Interesting details about Python int data type

Chetan Ambi
Jan 7 · 6 min read
Image for post
Image for post
Image by the author (generated from Canva)

Integer

Image for post
Image for post
Image by author

1) Division (/)

Image for post
Image for post

2) Floor division (//)

Image for post
Image for post
Source: Image generated from mathlearningcenter
Image for post
Image for post
Source: Image generated from mathlearningcenter
Image for post
Image for post
Image by author

3) Modulo (%)

a = b * (a // b) + (a % b)
a % b = a - (b * (a // b))
Image for post
Image for post
Image by author

4) Maximum value of int

Image for post
Image for post
Image by Author

5) Memory usage

import sys
a = 100
print(sys.getsizeof(a))
>> 28
b = 1111111111
print(sys.getsizeof(b))
>> 32
a = 100
print(a.__sizeof__())
>> 28
b = 1111111111
print(a.__sizeof__())
>> 32
a = 101
print(a.bit_length())
>> 7

6) Int constructor

int(5) 
>> 5
int(10.1)
>> 10
int('25')
>> 25
int('25', base=10)
>> 25
int('1110', base=2)
>> 14
int('765', base=8)
>> 501
int('F123', base=16)
>> 61731

Conclusion

Towards AI

The Best of Tech, Science, and Engineering.

Sign up for Towards AI Newsletter

By Towards AI

Towards AI publishes the best of tech, science, and engineering. Subscribe to receive our updates right in your inbox. Interested in working with us? Please contact us → https://towardsai.net/contact Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Thanks to Towards AI Team

Chetan Ambi

Written by

Data Science | Machine Learning | Python. Visit https://pythonsimplified.com/ for interesting articles on Python and Machine Learning

Towards AI

Towards AI is the world’s leading multidisciplinary science publication. Towards AI publishes the best of tech, science, and engineering. Read by thought-leaders and decision-makers around the world.

Chetan Ambi

Written by

Data Science | Machine Learning | Python. Visit https://pythonsimplified.com/ for interesting articles on Python and Machine Learning

Towards AI

Towards AI is the world’s leading multidisciplinary science publication. Towards AI publishes the best of tech, science, and engineering. Read by thought-leaders and decision-makers around the world.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store