468,470 Members | 2,108 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,470 developers. It's quick & easy.

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
Jan 22 '19 #1
1 1127
Luuk
1,043 Expert 1GB
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.

Similar topics

2 posts views Thread by Piyu | last post: by
5 posts views Thread by Raj | last post: by
10 posts views Thread by saipathakota | last post: by
thatos
1 post views Thread by thatos | last post: by
18 posts views Thread by ramu | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.