Home > other >  Values in PYthon new questions about the class of the self. * * * the return value
Values in PYthon new questions about the class of the self. * * * the return value

Time:09-22

[I] long code is not trouble, look, I said my problem,
First of all, my class is such a

In this class defines the attributes short, line 13 is a calculating formula of the distance, I tried, the dis variable is a number,

In the process of calculation, I have a step is:
S=s + li [p]. Every/li [p]. Short (t [I])
Every is a number of molecules, the question comes, if according to the above with the self to the dis. Dis assignment, the formula of the denominator can't calculate, display the following error, should be the denominator is not numeric types:


But I'm a piece of the attributes in the figure below added return dis, then can calculate the formula above,
If I don't return the dis, the following formula how to operate to reference this class - properties under calculate dis,

So I want to ask the main is that if this attribute (which is what I here short below) have multiple values dis1, dis2, dis3, calculate how individual calls outside the three dis value?
Big help thank you, I sprout new new to python

CodePudding user response:

My 'new, I wish who can speak some simple thank you

CodePudding user response:

If it is in the class, with the self. Try dis

CodePudding user response:

This function has no return value because of you, so can't calculate, plus the return after the return values for numeric type, can be calculated, can put the dis class attributes to class attribute calls need not add return return value

CodePudding user response:

I in this class the following dis a value, then I return the dis li [p]. Short [I] (t) this value is the dis,
But if I have dis1 middle class, dis2 dis3 three values, if return dis1, dis2, dis3, so I call how to separate one such as outside dis2?

CodePudding user response:

reference 4 floor lcf666666 response:
here in this class I dis a value, then I return the dis li [p]. Short [I] (t) this value is the dis,
But if I have dis1 middle class, dis2 dis3 three values, if return dis1, dis2, dis3, so I call how to separate one such as outside dis2?


If you just need to call dis alone, just return dis2, if it is
Need to return,
Dis1 dis2, dis3=function ()
Directly after using dis2 line

CodePudding user response:

Retrun (dis1 dis2, dis3)
Or
Retrun [dis1, dis2 dis3]

The caller access directly by a tuple or list corresponding subscript access can!
  • Related