开发者社区 问答 正文

python中的type和id

python中的type和id

展开
收起
montos 2020-04-16 20:30:39 744 分享
分享
版权
举报
2 条回答
写回答
取消 提交回答
  • 代码改变世界,我们改变代码

    type():

    1.做为类型获取,判断

    2.type()定义元类。

    id():

    获取对象内存地址。

    2020-04-20 09:34:18 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
  • 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 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答分类:
问答标签:
问答地址:
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等