Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Problem with adding arbitrary parrameters to __init__ method
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


I ran your code without issues. Please provide the full error you're getting, in code/error tags.
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 231 Dec-17-2019, 08:00 PM
Last Post: jasonashaw
  Adding markers to Folium map only adding last element. tantony 0 264 Oct-16-2019, 03:28 PM
Last Post: tantony
  Type error when reading in different data types on an __init__ method Dylanmull 3 536 May-09-2019, 02:05 PM
Last Post: buran
  problem with class method AmirAB 3 630 Feb-13-2019, 01:51 AM
Last Post: AmirAB
  Problem adding a float to a DoubleVar nortski 2 2,159 Apr-03-2018, 10:29 AM
Last Post: nortski
  Python capitalize() method problem Skipper 9 3,941 Jan-27-2018, 03:11 PM
Last Post: Skipper
  Would you unit test __init__ method? kilthar 1 11,363 Oct-18-2017, 05:31 PM
Last Post: snippsat
  Why is there an __init__ statement within the __init__ definition iFunKtion 7 2,904 Feb-06-2017, 07:31 PM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)