Python error How to solve Python ' takes exactly 1 argument (2 given) ' Python error

Source: Internet
Author: User
Tags in python

Python beginner, define urlconfig receive parameters, normal pass parameters, appear, give a parameter error problem,

After defining the function of class, it appears "' takes exactly 1 argument (2 given) ' Python error" at the time of the call.

After querying interesting ' takes exactly 1 argument (2 given) ' Python error, the original in Python, when using instance to invoke its class method, is quite the same as adding itself as the first argument in the call. As follows:

A.method (k)

is quite the same as:

A.method (A, k)

So, when you define a function, you need to first define self in the internal parameters of the function, such as:

Class Person ():

Def method (self, k):

...

If you want to call as a static function, you can identify it by adding "@staticmethod" above the definition function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.