Skip to content

Instantly share code, notes, and snippets.

@duncangh
Created September 18, 2019 22:03
Show Gist options
  • Select an option

  • Save duncangh/c45a68eed983e9edf57a16b0c37060fd to your computer and use it in GitHub Desktop.

Select an option

Save duncangh/c45a68eed983e9edf57a16b0c37060fd to your computer and use it in GitHub Desktop.
Python 'type' object to string.
# https://stackoverflow.com/questions/5008828/convert-a-python-type-object-to-a-string
type_variety_list : list = [
10,
'x',
lambda x: x,
set(),
dict(),
[]
]
types_of_elems_as_strings : list = [type(element).__name__ for element in type_variety_list]
print(types_of_elems_as_strings)
>>> ['int', 'str', 'function', 'set', 'dict', 'list']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment