Home >Backend Development >Python Tutorial >Detailed explanation of examples of constructors with parameters in Python

Detailed explanation of examples of constructors with parameters in Python

黄舟
黄舟Original
2017-05-31 14:41:501731browse

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')

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!

Statement:
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