DATA TYPES IN PYTHON

Python Free Tutorial

Variable data type is automatically determined by Python. Variables can store data of different types. Python has the following data types built-in by default, in these categories:

  1. None
  2. Numeric
  3. String
  4. List
  5. Tuple
  6. Set
  7. Dictionary (Map)

To find the data type we use built-in function type( ). Within the brackets, we must place the name of the variable or type of value which we we want to verify. So, for the following example we are placing different types of value to know its data-type. After executing the code, the result we obtain is “int”,”float” or data-type which indicates the value may be “int”,”float” or other.

None

If you have a variable and if this variable is not allocated with any value, we usually use a keyword as null in other languages, but we use None in Python.

NUMBERS

Python numbers include integer (int), floating numbers (float) and complex numbers (complex). You can get the data type of any object by using the type() function.

  1. Integers

Integers are the positive or negative numbers without decimal values. There is no limit for integer precision but the are limited by available memory size.

2. Floating Numbers

Floating Numbers are the positive or negative numbers including decimal values. A floating point number is accurate up to 15 decimal places. Float can also be scientific numbers with an “e” to indicate the power of 10. Division (/) always returns a float.

3. Complex

Complex Numbers are the combination of real part ‘x’ and imaginary part ‘y’ written in the form of x+yj.

why are complex numbers in Python denoted with ‘j’ instead of ‘i’?

Python adopted the convention used by electrical engineers. In that field, i is used to represent current and use j as the square root of -1
Typecasting

Typecasting is used in python to convert one data type to another. In this tutorial we will learn converting Integer into different bases like hex, oct, binary and also to float numbers.

SyntaxFunctionExampleoutput
int( )converts any data type to integerint(3.4)3
float( )converts any data type to floatint (3)3.000000
hex( )convert integer to hexadecimal stringhex(115)‘0x73’
oct( )convert integer to octal stringoct(32)”0o40′
other functions will be discussed in respective data types
Example : Convert meter to kilometer
Example : Convert Celsius to Fahrenheit

This page is contributed by Diwas & Sunil . If you like AIHUB and would like to contribute, you can also write an article & mail your article to  itsaihub@gmail.com . See your articles appearing on AI HUB platform and help other AI Enthusiast.

About Diwas

🚀 I'm Diwas Pandey, a Computer Engineer with an unyielding passion for Artificial Intelligence, currently pursuing a Master's in Computer Science at Washington State University, USA. As a dedicated blogger at AIHUBPROJECTS.COM, I share insights into the cutting-edge developments in AI, and as a Freelancer, I leverage my technical expertise to craft innovative solutions. Join me in bridging the gap between technology and healthcare as we shape a brighter future together! 🌍🤖🔬

View all posts by Diwas →

5 Comments on “DATA TYPES IN PYTHON”

  1. I have been exploring for a bit for any high-quality articles or blog posts on this kind of
    house . Exploring in Yahoo I at last stumbled upon this website.
    Reading this information So i am happy to show that I’ve a very
    good uncanny feeling I found out exactly what I needed.
    I such a lot indisputably will make certain to do not forget this website and give it a look
    regularly.

  2. Aw, this was an extremely nice post. Taking a few minutes and actual effort to make a very good article…
    but what can I say… I hesitate a whole lot and never seem to get nearly anything
    done. adreamoftrains webhosting

Leave a Reply

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