码迷,mamicode.com
首页 > 编程语言 > 详细

Python9-8

时间:2014-09-09 10:56:28      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   for   div   cti   sp   

python里一个class可以定义多个构造函数吗?

实现方法:

class A:
    def __init__(self, value):
        if isinstance(value, int):
            #整型构造函数
        else ifinstance(value, str):
            #字符串构造函数
        else:
            #其他构造函数........
可以用 *arg 和 **kwd 传入任意参数,不过函数里面要做处理就是啦可以用 *arg 和 **kwd 传入任意参数,不过函数里面要做处理就是啦

ipython中,如果想查看模块信息或模块属性等信息,可以在名称后面加“?”:

subprocess.call?
Type:       function
String Form:<function call at 0xb6e036bc>
File:       /usr/lib/python2.7/subprocess.py
Definition: subprocess.call(*popenargs, **kwargs)
Docstring:
Run command with arguments.  Wait for command to complete, then
return the returncode attribute.

The arguments are the same as for the Popen constructor.  Example:

retcode = call(["ls", "-l"])

 

Python9-8

标签:style   blog   color   io   ar   for   div   cti   sp   

原文地址:http://www.cnblogs.com/zxpgo/p/3961437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!