Justin Carrey
Justin Carrey

Reputation: 3851

Clarification about data types in python

One thing has been fascinating me since long time. In languages like c, we need to declare the data types for example, integer as int, character as char, etc. I mean we are giving information about the data type to the C compiler.
But in python, lets say i declare

c = 2  

Then the compiler interprets c as integer. And if i declare

c = "a"  

the compiler interprets c as a character. My doubt is how compiler knows how to assign appropriate data type to c without us explicitly declaring it. This may be a basic question for python experts, but shed some light on this

Upvotes: 4

Views: 308

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1124248

Python is a dynamically typed language.

The compiler doesn't interpret any type information when compiling python code. It's all just objects with methods, and it's up to your own code to use the values as it pleases.

Upvotes: 6

Related Questions