Quantcast
Channel: A different way to check the type of a list - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Thierry Lathuille for A different way to check the type of a list

$
0
0

Your code justly returns False, as you replaced the original meaning of list by your list. You shouldn't use the names of Python builtins as variable names.

So, change the name of your list and it will work as expected.

If it's too late for that, as you suggest in the edit to your question, you can still access the original list with:

list = [1,2,3]print(type(list) == __builtins__.list) # True

Or, the more recommended way, using isinstance instead of type(...) == ...:

print(isinstance(list, __builtins__.list))# True

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>