Python is dynamically typed and strongly typed, which means you don't need to declare types - they are deducted when you bind object to name. But types are always preserved and do not change until you explicitly rebind new object of different type to name ('variable').
What you call 'keywords' are only built-in utility functions, that return an object, so int()
returns default integer ('0') and str()
returns empty string. Thus if you call myvar = int()
you python first creates new integer object and later binds this object to name myvar
in current name scope. Later if you call print myvar
it checks current scope for name myvar
and passes object this name references to print
.
Now, if you for some reason want to make a variable with name 'int', let's say int = str
, Python allows that. But it does not mean you changed what name int
was referencing to (btw, Python does not allow modifying built-in types), you are only rebinding name you use in your program to other object. Thus if you later call othervar = int()
you create new empty string bound to othervar
, but that will be only in your current scope, it won't change how other modules can use int()
, as they have their own name bindings.
Look at code below to see how it works:
def int_fn():
return int()
def float_fn():
int = float
return int()
Now look what is returned:
In [26]: int()
Out[26]: 0
In [27]: float()
Out[27]: 0.0
In [28]: int_fn()
Out[28]: 0
In [29]: float_fn()
Out[29]: 0.0
Now about what your instructor said. int()
or str()
indeed are not keywords, and example above show that they are names like any other. But you should treat them as 'reserved words' that you should avoid using as names, unless you really, really know what you are doing and what consequences of your actions are (and that might be hard to learn).