Python Forum
Input as not default method parameter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Input as not default method parameter
#5
As mention input name is used,if not sure of build in names test it.
# Also not okay name is used 
>>> input
<built-in function input>
# foo can be use get a NameError
>>> foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'foo' is not defined

name 'foo' is not defined
(Mar-08-2019, 02:39 PM)dan789 Wrote: What´s the variable of that input? How can I use it´s value inside that function?
It can be None or any that user give that's the point of default arguments.
def function(param1, my_input=""):
    if my_input == '':
        return f'No argument given so i just return <{param1}> and <{repr(my_input)}>'
    return f"Ohh user want something else than '' so i return <{param1}> and <{my_input}"
Use:
# Will not get a error if give one argument
>>> function('hello')
"No argument given so i just return <hello> and <''>"

>>> function('hello', 999)
"Ohh user want something else than '' so i return <hello> and <999>"
>>> function('hello', 'world')
"Ohh user want something else than '' so i return <hello> and <world>"
Reply


Messages In This Thread
Input as not default method parameter - by dan789 - Mar-08-2019, 12:26 PM
RE: Input as not default method parameter - by snippsat - Mar-08-2019, 09:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 11,603 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  Zfill Method Parameter Confusion new_coder_231013 3 1,130 Dec-05-2022, 05:52 PM
Last Post: new_coder_231013
  function with 'self' input parameter errors out with and without 'self' called dford 12 3,320 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  [SOLVED] Input parameter: Single file or glob? Winfried 0 1,624 Sep-10-2021, 11:54 AM
Last Post: Winfried
  what would you call the input for the parameter(s) of a function you have defined? rix 3 2,529 Dec-16-2019, 12:04 AM
Last Post: rix
  def function default parameter expressions Skaperen 2 2,599 Aug-22-2019, 10:58 PM
Last Post: Skaperen
  Default setting for custom name input characteristics? beardelune 2 2,030 Aug-09-2019, 06:24 PM
Last Post: beardelune
  sqlite3 question - execute method with :parameter richalt2 2 7,667 May-20-2019, 05:35 PM
Last Post: woooee
  How to use a string method on user input Exsul 2 2,723 Mar-17-2019, 08:12 PM
Last Post: Exsul
  Input as function parameter dan789 1 2,128 Mar-08-2019, 05:19 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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