python 面向对象:
node2:/root/python/20200729#cat t5.py
# !/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(player))python 2:node2:/root/python/20200729#python2.7 t5.py
<type 'classobj'>
['__doc__', '__module__', 'print_role']
<type 'instance'>
['__doc__', '__module__', 'print_role']python 3
node2:/root/python/20200729#python3 t5.py
<class 'type'>
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'print_role']
<class '__main__.player'>
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'print_role']
node2:/root/python/20200729#面向对象理论中的“ 类 ”和“ 对象 ”这两个基本概念,在 Python 内部都是通过对象实现的,这是 Python 最大的特点。