Mustafa
Mustafa

Reputation: 13

Why does Python treats datatype keywords like (int) as variables?

for instance, if I want to store 5 in a variable named int, I am able to do it. However, in statically typed languages like C/C++, I can't use datatype names as variables. Why is that not the case in python?

int = 5
print(int) 

5

I am also able to do the same with list/tuple/dict keywords.

Upvotes: 1

Views: 58

Answers (1)

bicarlsen
bicarlsen

Reputation: 1371

Python has a set of built-in functions. When you redefine int you're simply overwriting the global symbol. This is as opposed to a reservered keyword which gives a SyntaxError if you try to redefine it.

Upvotes: 2

Related Questions