开发者社区> 问答> 正文

python中的type和id

python中的type和id

展开
收起
montos 2020-04-16 20:30:39 704 0
2 条回答
写回答
取消 提交回答
  • 代码改变世界,我们改变代码

    type():

    1.做为类型获取,判断

    2.type()定义元类。

    id():

    获取对象内存地址。

    2020-04-20 09:34:18
    赞同 展开评论 打赏
  • type函数返回一个对象的类型。举个例子:

    print(type(''))
    # Output: <type 'str'>
    
    print(type([]))
    # Output: <type 'list'>
    
    print(type({}))
    # Output: <type 'dict'>
    
    print(type(dict))
    # Output: <type 'type'>
    
    print(type(3))
    # Output: <type 'int'>
    

    id()函数返回任意不同种类对象的唯一ID,举个例子:

    name = "Yasoob"
    print(id(name))
    # Output: 139972439030304
    
    2020-04-16 20:30:59
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载