Python3: Can use other than 'self' as a 1st parameter of methods?

hoge1e3

Can this code

class Point:
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def __str__(self):
        return "Point({},{})".format(self.x,self.y)
p=Point(3,5)
print(p)

be modified to following code?

class Point:
    def __init__(p,x,y):
        p.x=x
        p.y=y
    def __str__(p):
        return "Point({},{})".format(p.x, p.y)
p=Point(3,5)
print(p)

It seems to be worked in this case. But it is so naive case. I wonder using other than 'self' will cause some problem in some situations.

Priyank-py

The first argument is the reference to the bound variable or object. Its convention to use self but anything else will also work. check the doc here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Removing 1st Index element causes a form not to post other indexes greater than 1st

1st SQL request slower than other with cold cache

What hashing algorithms would you recommend I use in Python3 that can generate a random salt, other than bcrypt?

Passing 'self' parameter during methods decorating in Python

How can I use d3-scale-chromatic functions with a domain other than [0, 1]?

Can I customize the `resources` helper in my routes to use a parameter other than \:id?

Why overload the constructor rather than use methods that return self references?

Unable to update other table rows other than 1st created

How to use self parameter, @staticmethod keyword inside a class and its methods

SQL/VBA: How to group by a fiscal year starting from a day other than 1st day of month

How can I unzip file encrypted with algorithm other than PKZIP in Python3?

Why can't I use model methods as defaults? What is self in Python/Django models anyway?

Can an anonymous class in Java have other methods than his superclass?

How to use in Angular inside an arrow function an object property (deeper than 1st level) sent by input?

When to use self, &self, &mut self in methods?

How Can I Use Sort or another bash cmd To Get 1 line from all the lines if 1st 2nd and 3rd Field are The same

Laravel: How to use a parameter other than user id in a URL

What other <tag> can be use to fire AJAX other than <button>?

Can I use other prefixes other than 'is' in WCMUsePojo boolean getters?

Better way to list all directories in Python other than self?

Use `self` as a default parameter

Use self as parameter in a singleton

Can we use expose method to return other reactive variables and computed properties like methods in vue 3?

How to modify the 1st element of a collection in a slightly different way than other in Elixir using Enum.map?

Can a Plain Old Java Object/POJO have methods that deal with business logic other than getter/setter methods?

Ruby - instance methods: why can i use getter without self, but setter only with self

How can I use different name for a function other than main in python?

Python - Looping through dataframe using methods other than .iterrows()

PHPUnit - Use $this or self for static methods?