Python Forum
Problem with adding arbitrary parrameters to __init__ method
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with adding arbitrary parrameters to __init__ method
#1
Hello Python community,

At the moment i'm starting to learn Python and it is going well, but I'm a bit stuck figuring out why the def __init__ wont take a parameter with a single asterisk.
The one with two works fine, anybody that knows if this even can work or is there something wrong in my code?

Here is the code:
print("\nAnother class for users:")
class User():
    """Describing a user."""
    def __init__(self, first_name, last_name, *languages, **information):
        self.fullname = first_name + " " + last_name
        self.languages = languages
        self.information = information



Thanks in regards

Mudo

Reply
#2
I ran your code without issues. Please provide the full error you're getting, in code/error tags.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem usage of static method akbarza 5 455 Feb-03-2024, 07:43 AM
Last Post: paul18fr
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 870 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  problem adding two numpy arrays djf123 2 2,042 Aug-09-2022, 08:31 PM
Last Post: deanhystad
  Django: Adding Row Data To Existing Model Instance Question/Problem. Steven_Pinkerton 1 1,214 Aug-09-2022, 10:46 AM
Last Post: Addweb
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 2,017 Dec-17-2019, 08:00 PM
Last Post: jasonashaw
  Adding markers to Folium map only adding last element. tantony 0 2,095 Oct-16-2019, 03:28 PM
Last Post: tantony
  Type error when reading in different data types on an __init__ method Dylanmull 3 2,748 May-09-2019, 02:05 PM
Last Post: buran
  problem with class method AmirAB 3 3,332 Feb-13-2019, 01:51 AM
Last Post: AmirAB
  Problem adding a float to a DoubleVar nortski 2 5,291 Apr-03-2018, 10:29 AM
Last Post: nortski
  Python capitalize() method problem Skipper 9 10,510 Jan-27-2018, 03:11 PM
Last Post: Skipper

Forum Jump:

User Panel Messages

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