Python Forum
Why Person() takes no arguments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why Person() takes no arguments
#1
Hi, can anyone tell me why my code below does not work, with the TypeError: Person() takes no arguments? Thanks a lot in advance!


class Person:
    def _int_(self, name, age):
        self.name = name
        self.age = age
        
    def detail(self):
        print (self.name)
        print (self.age)
        
obj1 = Person("santos", 18)
obj1.detail()
Reply
#2
Hello, you want
    def __init__(self, name, age):
with an extra I and extra underscore on each side instead of
    def _int_(self, name, age):
Reply
#3
(Oct-22-2018, 03:44 PM)j.crater Wrote: def _init_
And also two underscores on each side, called a "dunder", for double underscore: def __init__.
Reply
#4
Got it, thank you so much @j.crater
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Class takes no arguments bily071 2 633 Oct-23-2023, 03:59 PM
Last Post: deanhystad
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,935 Oct-17-2022, 06:29 PM
Last Post: paulo79
  Checking the number of arguments a function takes Chirumer 3 2,153 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  Class Takes No Arguments horuscope42 4 4,817 Oct-26-2020, 11:10 PM
Last Post: not_username1234
  OOP hellp (simple class person) onit 4 2,537 Jul-14-2020, 06:54 PM
Last Post: onit
  Class takes no arguments Nazartfya 2 4,569 Jun-27-2020, 12:45 PM
Last Post: Nazartfya
  Why Car() takes no arguments louis216 2 2,606 Jun-25-2020, 03:16 AM
Last Post: louis216
  random.choice() takes two positional arguments, but three were given. ShakeyPakey 5 11,663 May-31-2020, 03:13 PM
Last Post: deanhystad
  Question() takes no arguments jwrcfv 2 3,103 Apr-02-2020, 06:08 PM
Last Post: jwrcfv
  add() takes 2 positional arguments but 3 were given Man_from_India 3 5,770 Feb-10-2020, 05:08 PM
Last Post: Man_from_India

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020