Python语言基础(三): 类 - 简单例子

简介: 类class Person:    def setName(self, name):        self.name = name    def getName(self):        return self.

class Person:
     def setName(self, name):
        self.name = name
     def getName(self):
         return self.name
     def greet(self):
         print  " Hello, I'm %s. " % self.name

person1 = Person()
person1.setName( " David ")
person1.greet()

运行结果:

Hello, I'm David.

 

目录
相关文章
|
6天前
|
索引 Python
python-类属性操作
【10月更文挑战第11天】 python类属性操作列举
11 1
|
7天前
|
Java C++ Python
Python基础---类
【10月更文挑战第10天】Python类的定义
13 2
|
14天前
|
设计模式 开发者 Python
Python类里引用其他类
Python类里引用其他类
16 4
|
16天前
|
设计模式 开发者 Python
Python 类中引用其他类的实现详解
Python 类中引用其他类的实现详解
19 1
|
16天前
|
JSON 缓存 API
在 Python 中使用公共类处理接口请求的响应结果
在 Python 中使用公共类处理接口请求的响应结果
15 1
|
19天前
|
机器人 关系型数据库 Python
【Python篇】Python 类和对象:详细讲解(下篇)
【Python篇】Pyt hon 类和对象:详细讲解(下篇)
20 2
|
19天前
|
算法 Python
【Python篇】Python 类和对象:详细讲解(中篇)
【Python篇】Python 类和对象:详细讲解(中篇)
19 2
|
19天前
|
存储 C++ Python
【Python篇】Python 类和对象:详细讲解(上篇)
【Python篇】Python 类和对象:详细讲解(上篇)
16 2
|
28天前
|
前端开发 Python
Python编程的面向对象有哪些(二)
Python编程的面向对象(二)—类的多态
21 7
|
27天前
|
IDE Java 开发工具
Python类与面向对象
Python类与面向对象