Python 面向对象

# -*- coding: utf-8 -*-
"""
Created on Thu Oct 18 11:26:31 2018

@author: admin
"""

#面向对象

class Student:
    __school='csu'
    def __init__(self,name,age,score=100):
        self.name=name
        self.age=age
        self.__score=score   # 私有成员 __
    
    def get_information(self):
        print("name:",self.name," age:",self.age)
        print("name:{0} , age:{1}".format(self.name,self.age))
        print("name:%s , age:%s ,score:%s" %(self.name,self.age,self.__score))
    
    def set_information(zgl,name,age):
        zgl.name=name
        zgl.age=age
    
s1=Student('zgl',26)
s1.get_information()
s1.set_information('zgl',25)
s1.get_information()
s1.age=1
s1.get_information()
#s1.__score=12
#print(s1.age)
#print(s1.__school)
#print(s1.__score)
#

s2=Student('lj',20)
print(type(s1)==type(s1))
print(isinstance(s1,Student))
print(isinstance(s2,int))

print(dir('zgxdd'))  # 获取一个对象的属性和方法
print('zgxdd'.__sizeof__())

# setattr,getattr,hasattr 操作一个对象的状态
help(setattr)

import os
print(os.path)
print(dir(os))

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值