Python 含参构造函数实例详解

yipeiwu_com7年前Python基础

本篇博文主要介绍在Python3中如何构造含参构造函数

样例如下:

class MyOdlHttp:
  username = ''
  password = ''

  def __init__(self, username, password):
    self.username = username
    self.password = password
    print(username)

my_old_http = MyOdlHttp('admin', '123')

输出结果毫无疑问是 admin\n 123\n

通过样例可以看到主要是复写了init 函数的方式来完成的。

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关文章

Python 查找list中的某个元素的所有的下标方法

如下所示: #!/usr/bin/env python #_*_ coding:utf-8 _*_ name = ['hello', 'world', 'a', 'b', 'c',...

使用Python操作FTP实现上传和下载的方法

搭建ftp服务器server端 # -*- coding:utf-8 -*- from pyftpdlib.authorizers import DummyAuthorizer fr...

Python 把序列转换为元组的函数tuple方法

tuple函数功能和list功能很相似,以序列为参数并把它转换为元组 >>> tuple([1,2,3]) (1, 2, 3) >>> tuple...

flask中过滤器的使用详解

过滤器 过滤器的本质就是函数。有时候我们不仅仅只是需要输出变量的值,我们还需要修改变量的显示,甚至格式化、运算等等,而在模板中是不能直接调用 Python 中的某些方法,那么这就用到了...

pip matplotlib报错equired packages can not be built解决

pip安装matplotlib 在centos6.5 64bit上用pip安装matplotlib时候报错: * The following required packages ca...