Home > Backend Development > Python Tutorial > Python类的用法实例浅析

Python类的用法实例浅析

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 11:17:47
Original
1305 people have browsed it

本文实例讲述了Python类的用法。分享给大家供大家参考。具体如下:

先看一段代码:

#!/usr/bin/env python
class Test:
  def __init__(self,msg="hello"):
    self.wel=msg
    print "init"
  def go(self,name,do):
    print self.wel+"go! "+name+" "+do
d=Test("hi,")
d.go("naughty","fight")

Copy after login

上面的代码演示了:

1、构造函数以及带参数(参数有默认值)构造函数

2、构造类实例

3、使用类实例调用类方法

希望本文所述对大家的Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template