[Tutor] Why is it invalid syntax to have a particular dictionary value as an argument?
boB Stepp
robertvstepp at gmail.com
Mon Apr 6 16:54:47 CEST 2015
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> d = {'n': 'Print me!'}
>>> d
{'n': 'Print me!'}
>>> d['n']
'Print me!'
>>> def func(d['n']):
SyntaxError: invalid syntax
>>> def func(d):
print d['n']
>>> func(d)
Print me!
The plain text does not show it, but in the invalid syntax the "[" is
highlighted red.
Why is it invalid syntax to pass a particular dictionary value in a
function? Or does it require a different form to do so?
Thanks!
--
boB
More information about the Tutor
mailing list