Python 判断变量类型

妖狐艹你老母 2022-03-12 17:52 426阅读 0赞

方法如下:

  1. # Variables of different types
  2. i = 1
  3. f = 0.1
  4. s = "Hell"
  5. l = [0, 1, 2]
  6. d = {0:"Zero", 1:"One"}
  7. t = (0, 1, 2)
  8. b = True
  9. n = None
  10. All of the following return True:
  11. isinstance(i, int)
  12. isinstance(f, float)
  13. isinstance(s, str)
  14. isinstance(l, list)
  15. isinstance(d, dict)
  16. isinstance(t, tuple)
  17. isinstance(b, bool)
  18. What about None? For that, there is always:
  19. n is None

发表评论

表情:
评论列表 (有 0 条评论,426人围观)

还没有评论,来说两句吧...

相关阅读