problem with the following piece of code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • himani bansal
    New Member
    • Nov 2018
    • 6

    problem with the following piece of code

    can you explain the problem with the following piece of code-
    >>> def func(n=[]):
    #playing around
    pass
    >>> func([1,2,3])
    >>> func()
    >>> n
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    I do see different results:
    Code:
    C:\temp>python
    ActivePython 3.5.3.3505 (ActiveState Software Inc.) based on
    Python 3.5.3 (default, May 16 2017, 01:12:46) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> def func(n=[]):
    ... #playing around
    ...   pass
    ...
    >>> func([1,2,3])
    >>> func()
    >>> n
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'n' is not defined
    >>>
    You are also not explaining what 'pass' should do?

    Comment

    Working...