在python中使用object打印输出

2024-06-16 12:20:55 发布

您现在位置:Python中文网/ 问答频道 /正文

class hive:
   def abc(str):
      name = str
      return name + ' welcome'

def main():
  obj = hive()
  print('enter name')
  string = input()
  print(obj.abc(string))

if __name__ == "__main__": main()

I want to print name with welcome string concatenated with it,but I can't be able to do so and I am getting the error below :

C:\Users\SHUBHAM TANDAN\Desktop\python>class.py 
enter name
shubham
Traceback (most recent call last):
File "C:\Users\SHUBHAM TANDAN\Desktop\python\class.py", line 12, in <module>
if __name__ == "__main__": main()
File "C:\Users\SHUBHAM TANDAN\Desktop\python\class.py", line 10, in main
print(obj.abc(string))
TypeError: abc() takes 1 positional argument but 2 were given

Can anyone please help me find the error in the above code ?


Tags: thenameinpyobjstringmainusers