str = "a b c"
eval(str) # throws error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
a b c
^
SyntaxError: invalid syntax
aberdas Eingabeformat von eval in Python zu verstehen
str = "\'a b c\'"
eval(str) # prints
'a b a'
Was ist der Unterschied zwischen den zwei Bedingungen ist. Warum wird das Zeichen benötigt? ?
Versuchen Sie, 'a b c' in eine Python-Shell einzugeben. Dann probiere "a b c". – miradulo
Eins ist ein String-Literal (das eine, das funktioniert) das andere ist ein Syntaxfehler ... was bekommen Sie nicht genau? Was glaubst du, was eval ist? –
Beachten Sie auch, 'eval ('' a b c '')' ist total albern. Verwenden Sie einfach "" 'a b c' "' –