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:
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.
- 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.
Syntax | Function | Example | output |
int( ) | converts any data type to integer | int(3.4) | 3 |
float( ) | converts any data type to float | int (3) | 3.000000 |
hex( ) | convert integer to hexadecimal string | hex(115) | ‘0x73’ |
oct( ) | convert integer to octal string | oct(32) | ”0o40′ |
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.
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.
I got this web site from my friend who informed
me regarding this web page and now this time I am browsing
this web site and reading very informative content at this time.
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