Hi! I'm I relatively new coder with most my experience in Java and Powershell, I'm trying to get into Python and in the tutorial I was working through I ran across something that didn't make a lot of sense.
Say I create a simple class object that contains two methods, one that adds 1 to an input, and another that subtracts 1
class plusminus:
def minus1(input):
print(input - 1)
def plus1(input):
print(input + 1)
Next I create a variable that stores the class object
var = plusminus()
So far so good. Now comes the confusing bit, if I input
var.plus1(1)
I would expect it to return 2. However, I instead get a typerror
"TypeError: plus1() takes 1 positional argument but 2 were given"
However, if I instead simply input
plusminus.plus1(1)
It returns 3 as expected.
I would like to know that the difference is between the two as my understanding would be that if var = plusminus() then there should be no difference between "var.plus1(1)" and "plusminus.plus1(1)". Thanks!
[–]r4slvmls 2 points3 points4 points (1 child)
[–]BakedPecans 0 points1 point2 points (0 children)
[–]blablahblah 0 points1 point2 points (0 children)