Python Forum
Problem with adding arbitrary parrameters to __init__ method - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problem with adding arbitrary parrameters to __init__ method (/thread-24161.html)



Problem with adding arbitrary parrameters to __init__ method - sebastianvdn - Feb-02-2020

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




RE: Problem with adding arbitrary parrameters to __init__ method - micseydel - Feb-03-2020

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