Python 3.3.2 在 If-else 中使用 ":"语法错误

标签 python python-3.3 python-idle

>>> x = 15
if (x/2)*2 == x:
    print ('Even')
    else:
    print ('Odd')

SyntaxError: multiple statements found while compiling a single statement
>>> x = 15 if (x/2)*2 == x:
    print ('Even')
    else:
    print ('Odd')

SyntaxError: invalid syntax 

最佳答案

在Python中你不能在一行中写多个语句,而是这样写

x = 15 
if (x/2)*2 == x: 
   print ('Even') 
else: 
    print ('Odd')

这里:

enter image description here

得到了

enter image description here

关于Python 3.3.2 在 If-else 中使用 ":"语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18013813/

相关文章:

python - 'str' 对象在 Python3 中没有属性 'decode'

python - IDLE中奇怪的变量多重赋值python

python - 如何让 .py 文件直接打开到 Idle

python - 如何使用正则表达式搜索 unicode 文本并查找包含重复字母的单词?

python - 如何对非唯一项列表使用字典推导式

python - 尝试使用 requests-html 抓取 JS Web 时出现问题(Python 3.6)

python - 在 Python 3.3 中使用 pySerial

windows - 在 Python 3.3 中捕获 TimeoutExpired 异常

python - Django + 后台任务如何初始化

python - 如何在 Ubuntu 10.04 中设置 python IDLE 以使用 pythonpath 变量