python 中的类和实例
程序员文章站
2022-06-16 20:10:43
...
# !/usr/bin/env python
# -*- coding: utf-8 -*-
class player(): ##定义一个类
def print_role(self): ##定义一个实例方法
return 'aaaaaaaa'
print type(player)
print dir(player)
user1=player() ##类的实例化
print type(user1)
print dir(user1)
print user1.print_role()
C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled2/socket/fun15.py
<type 'classobj'>
['__doc__', '__module__', 'print_role']
<type 'instance'>
['__doc__', '__module__', 'print_role']
aaaaaaaa
Process finished with exit code 0