Python: Dynamic typed

According to wikipedia, “A programming language is said to be dynamically typed when the majority of its type checking is performed at run-time as opposed to at compile-time. In dynamic typing values have types, but variables do not; that is, a variable can refer to a value of any type. ”

In statically typed language (like Java), you define a variable of certain type during declaration and its bound to that data type. Assigning the variable with values from different data type is caught during compile-time.

But in dynamically typed languages (like Python), every variable name is bound to an object. Based on the type of value assigned, data type of variable gets decided.

>>> var = 'some string'
>>> print type(var)
<type 'str'>
>>> var = 4
>>> print type(var)
<type 'int'>

You must have observed, the type of variable var changed based on the value assigned to it, hence dynamically typed.

About Chetan Giridhar

Always learning

Posted on March 7, 2012, in Python and tagged , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

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

You are commenting using your 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


Get every new post delivered to your Inbox.

%d bloggers like this: