What does "other" mean in python?
So i just started learning object oriented programming in python 3 and i came across the "
__add__" method and i don't understand what " other " is and what it does. I tried to look on the internet for an answer but i found nothing, here is an example of my code:
import math class MyClass: def __init__(self, x, y): self.x = x self.y = y def __add__(self, other): f = self.x + other.x e = self.y + other.y
what " other " is and what it does.
It is the name of a parameter. The parameter
other is (for example) another instance of
MyClass. Take the following example:
a = MyClass(1, 2) b = MyClass(3, 4) # the next line calls MyClass.__add__ on the instance a c = a + b
In this case
The code for
__add__ in your example is incomplete, it should really return a new
def __add__(self, other): f = self.x + other.x e = self.y + other.y return MyClass(f, e)
What does the 'R' number of coronavirus actually signify?, What does the 'R' number of coronavirus actually signify? One figure in particular is being closely scrutinised as ministers decide when to end The :-) notation is known as a smiley, and means that the statement it follows was intended as humor. When you tilt your head to the side, you see that : is the eyes, - the optional nose, and ) is the mouth.
other in this case is called a "parameter". A parameter is kind-of like a "hole" in a function definition that you can later fill with a concrete value called an "argument".
For example, in
def foo(a, b): return a + b
b are parameters to the function
foo, and when you call
5 are arguments which are bound to the parameters, such that for this particular invocation of the function, the code that is executed is
3 + 5
What does 25% occupancy for Texas businesses reopening Friday , AUSTIN -- Restaurants can begin allowing customers Friday in limited numbers statewide. The action is the result of Gov. Greg Abbott lifting a Define does. does synonyms, does pronunciation, does translation, English dictionary definition of does. v. Third person singular present tense of do1. vb a form of the present tense of do1 n taboo slang South African a foolish or despicable person n., pl.
What Did Hubble See on Your Birthday?, Colleges have released a flurry of statements saying that they will reopen campuses in the fall. Will that plan bear out? What are 3 subsystems of a technology lab. What is the answers to module 18 foolproof. Which was not a result of the baby boom that followed world war ii answers APEX
The Fox (What Does the Fox Say?), To help stop the spread of COVID-19, Governor Inslee has asked Washington residents to stay home. You might have questions about what that means. What does this quote mean?how the quote below relates to contradictions of Wang Lung’s actions since his return from the South. - No ledge seeker. What does this face mean -///- ? - derp_askingthings. « Older Entries.
What does an 'intent' to reopen mean?, Most mutations don't really change how the virus functions. Below is a glimpse at an imaginary virus. It's doing what all viruses do: entering a cell, o.O = surprise, shock, yawn. Was this answer helpful? what does ;v; mean? my friend used it in a text but I have no idea what it means. Was this answer helpful? Was this answer helpful? Was this answer helpful? it is an excited smiley. like ^v^ but then he has the commas from the ; which add two hands holding his cheeks. its just some weird
What does it mean to stay home, Millions unable to do their job due to coronavirus will have their wages paid by a new scheme. :) is used in texting, and it is usually changed to something like: There are many different emojis used, in their letter format. :P is a tongue sticking out, :D is a huge grin, and :| is a sort of neutral face. Also note, you can see what it looks like by tilting your head and making the colons (:) at the top.
- If you create an instance from
MyClassfor example with name
mand if you wanna add another number to
otherwill hold that number or object in
m + another_obj.
- feel free to accept an answer