How to get a variable data type in Python 3 All In One
How to get a variable data type in Python 3 All In One
typeof
in js
type(var)
& isinstance(var, type)
#!/usr/bin/env python3
# mix list
lt = [1, 2, {'k': 'v'}, {1, 'str'}]
dt = dict()
for [i, item] in enumerate(lt):
print(i, item)
dt[i] = item
print('\n', dt)
st = {'str', 3}
print('\n', st)
print("type(st) =", type(st))
# type(st) = <class 'set'>
print(isinstance(st, set))
# True
map = {'key1': 1, 'key2': 1}
print('\n', map)
print("type(map) =", type(map))
# type(map) = <class 'dict'>
print(isinstance(map, dict))
# True
"""
$ py3 ./py-set.py
$ python3 ./py-set.py
"""
python env
$ ls -alth /usr/bin/ | grep env
-rwxr-xr-x 1 root wheel 132K Jun 15 18:08 env
-rwxr-xr-x 1 root wheel 131K Jun 15 18:08 printenv
$ which python
python: aliased to /usr/local/bin/python3
$ which python3
/usr/bin/python3
$ which py3
py3: aliased to python
shebang
env
#!
#!/usr/bin/env python3
#!/usr/bin/python3
demos
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
https://stackoverflow.com/questions/152580/whats-the-canonical-way-to-check-for-type-in-python
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17715720.html
未经授权禁止转载,违者必究!