Detailed explanation of examples of constructors with parameters in Python

黄舟
Release: 2017-05-31 14:41:50
Original
1685 people have browsed it

This article mainly introduces the related information of Python Constructor with parameters detailed examples. Friends in need can refer to it

This blog post mainly introduces How to construct a parameter-containing constructor in Python3

The example is as follows:

class MyOdlHttp:
  username = ''
  password = ''

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

my_old_http = MyOdlHttp('admin', '123')
Copy after login

The output result is undoubtedly

admin\n 123\n

passed As you can see from the sample, it is mainly accomplished by overriding the init function.

The above is the detailed content of Detailed explanation of examples of constructors with parameters in Python. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!