zoukankan      html  css  js  c++  java
  • python setattr,delattr()

    1 setattr():

    setattr()表示你可以通过该方法,给对象添加或者修改指定的属性。

    setattr()方法接受3个参数:setattr(对象,属性,属性的值)

    2 delattr():

    而delattr()表示你可以通过该方法,删除指定的对象属性。

    delattr方法接受2个参数:delattr(对象,属性)

    下面是代码的应用

    #encoding=utf-8

    class student(object):

       def __init__(self,name,age):

           self.name = name

           self.age = age


    sinfo = student('xiaoming',32)

    print sinfo.name

    setattr(sinfo,'python','haha')##和:sinfo.python = 'haha' 效果一样

    print sinfo.__dict__

    delattr(sinfo,'python')##和del sinfo.python效果一样

    print sinfo.__dict__
  • 相关阅读:
    jquery02
    jquery01
    oracle04_plsql
    oracle03
    oracle02
    oracle01
    selenium
    爬取京东商品信息并保存到MongoDB
    python pymongo操作之增删改查
    MongoDB 数据库表删除
  • 原文地址:https://www.cnblogs.com/wanpython/p/3117940.html
Copyright © 2011-2022 走看看