What is the method in python
Methods are used to describe the behavior of an object.
Methods defined in a class can be roughly divided into four categories: public methods, private methods, static methods, and class methods.
Public methods and private methods generally refer to instance methods belonging to an object.
The name of a private method starts with two underscores __.
Each object has its own public and private methods. In these two types of methods, you can access members belonging to classes and objects.
Public methods are called directly through the object name,
Private methods cannot be called directly through the object name, and can only be called through self in the instance method Or call it externally through special methods supported by python.
All instance methods of a class must have at least one parameter named self, and must be the first formal parameter of the method. The self parameter represents the object itself.
You need to prefix self when accessing instance properties in an instance method of a class, but you do not need to pass this parameter when calling an object method externally through the object name. If When externally calling a public method belonging to an object through a class name, you need to explicitly pass an object name to the self parameter of the method to clearly specify which object's data member is to be accessed.
Both static methods and class methods can be called through class names and object names, but they cannot directly access members belonging to the object, only members belonging to the class. Generally, cls is used as the first parameter of a class method, representing the class itself. There is no need to pass a value for this parameter when calling the class method.
Related learning recommendations: python tutorial
The above is the detailed content of What is the method in python. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Using python in Linux terminal...

Fastapi ...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
