About 702,000 results
Open links in new tab
  1. How to define default value if empty user input in Python?

    Here I have to set the default value if the user will enter the value from the keyboard. Here is the code that user can enter value: input = int(raw_input("Enter the inputs : ")) Here the value wi...

  2. python - How do I add default parameters to functions when …

    The empty dict passed as a default parameter is the same dict for every call. So if the function mutates it then the default next time will be the mutated value from last time.

  3. Is there shorthand for returning a default value if None in Python ...

    x or default is an antipattern! It is a frequent source of errors that are hard to debug, because for many subtle reasons x could evaluate to false even if it is the desired value.

  4. python - How to set default value for variable? - Stack Overflow

    In the exact scenario you present, you can use default values for arguments, as other answers show. Generically, you can use the or keyword in Python pretty similarly to the way you use || …

  5. python - Get a function argument's default value? - Stack Overflow

    In python, all the arguments with default value come after the arguments without default value. So the mapping should start from the end till you exhaust the default value list.

  6. python - Return a default value if a dictionary key is not available ...

    Accessing the key and catching the exception is perfectly okay in Python. It is even a well known and oft-used design pattern. If you return None instead, it becomes impossible to store None …

  7. default value - Proper way to use **kwargs in Python - Stack …

    Jul 8, 2009 · What is the proper way to use **kwargs in Python when it comes to default values? kwargs returns a dictionary, but what is the best way to set default values, or is there one? …

  8. python - Setting a Default Value in an Entry box in Tkinter - Stack ...

    Setting a Default Value in an Entry box in Tkinter Asked 10 years, 4 months ago Modified 9 years, 11 months ago Viewed 29k times

  9. Best practice for setting the default value of a parameter that's ...

    Mar 2, 2012 · 3 For mutable object as a default parameter in function- and method-declarations the problem is, that the evaluation and creation takes place at exactly the same moment. The …

  10. How should I declare default values for instance variables in Python?

    However, if I do not require a class variable, but only need to set a default value for my instance variables, are both methods equally good? Or one of them more 'pythonic' than the other? …