python类型检查和类型转换

  1. 类型检查

     type()用来检查值的类型 (整型、浮点型、布尔值、字符串、空值)
     该函数会将检查的结果作为返回值返回,可以通过变量来接收函数的返回值

    print(type(1))         # <class 'int'>
    print(type(1.5))       # <class 'float'>
    print(type(True))      # <class 'bool'>
    print(type('hello'))   # <class 'str'>
    print(type(None))      # <class 'NoneType'>
    
    a=type(123)
    print('123数字类型检查结果返回值:',a)
    # 123数字类型检查结果返回值: <class 'int'>
  2. 类型转换

猜你喜欢

转载自www.cnblogs.com/FlyingLiao/p/11142225.html