By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,345 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

problem with the following piece of code

P: 5
can you explain the problem with the following piece of code-
>>> def func(n=[]):
#playing around
pass
>>> func([1,2,3])
>>> func()
>>> n
Jan 22 '19 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 998
I do see different results:
Expand|Select|Wrap|Line Numbers
  1. C:\temp>python
  2. ActivePython 3.5.3.3505 (ActiveState Software Inc.) based on
  3. Python 3.5.3 (default, May 16 2017, 01:12:46) [MSC v.1900 64 bit (AMD64)] on win32
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> def func(n=[]):
  6. ... #playing around
  7. ...   pass
  8. ...
  9. >>> func([1,2,3])
  10. >>> func()
  11. >>> n
  12. Traceback (most recent call last):
  13.   File "<stdin>", line 1, in <module>
  14. NameError: name 'n' is not defined
  15. >>>
You are also not explaining what 'pass' should do?
Jan 27 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.