On 24/05/2021 07:21, hw wrote: >> Inside the function f() the name 'x" shadows the global "x"; references >> to "x" are to the function's local vairable. Which is very desireable. > > If it works that way, I would consider it an entirely different > variable.
Remember that in Python variables are just names. They are literally keys to a dictionary and the value that is associated with the name can change. It may be a literal value, a function or a class or a type. Names can be anything that is not a reserved word. (Provided they keep within the naming grammar rules) Also, unlike some other languages, type names are not reserved words. >>>> by naming a variable like a variable type, I would think it is a bad >>>> idea for python to allow this without warning. It does warn you, that's what the message it printed said: print(isinstance(int, float)) TypeError: isinstance() arg 2 must be a type or tuple of types There is only on possible cause for that error. float is not a type or a tuple of types. Therefore you must have changed it somewhere. Since this is the first place in the program that python can identify an error, this is where the message gets printed. You are working in a dynamic language that allows you to do whatever you want to do. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list