Knowing data type of a variable!

As we all know that Python changes the type of variable during run time as per it’s need.
But sometimes we need to see type of variable before performing some operations or calculations further on that variable.
So,in order to find data type of a variable use in built function type()

>>> firstNumber = 10

>> type(firstNumber)

<class ‘int’>

You can find the limits in the sys module.

>> import sys
>>> print sys.maxint
2147483647

The above statement works in Python 2.x only.

But note that modern Python versions will silently convert
data types when calculation results no longer fit in current one.

Python’s long integers can be as large as you like, as long
as your computer doesn’t run out of memory…

 

>> number = 10**545465415454

The above code causes system to freeze!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: