[英]Simple if statement on python interpreter
Environment: 环境:
I am having problems running this simple lines of code in the python interpreter, this is an only if statement or alone if statement. 我在python解释器中运行这些简单的代码行时遇到问题,这是一个唯一的if语句或单独的if语句。
n = 5
if n == 4:
print('n=4')
print('done')
This must print the word "done", but what am I doing wrong? 这必须打印“完成”这个词,但我做错了什么?
The interpreter gives you a line after blocks to leave blank for the interpreter to know your block is over (or to put an else
, etc.). 解释器为您提供了一个块之后的行,以便为解释器留出空白以便知道您的块已经结束(或者放置
else
等)。 Putting something there makes it freak out. 把东西放在那里会让它变得怪异。 Just leave it that line blank and wait for the next
>>>
before your print('done')
. 只需将该行留空并在
print('done')
之前等待下一个>>>
print('done')
。
>>> n = 5
>>> if n == 4:
... print('n=4')
...
>>> print('done')
done
If it is an older version of python, forget the brackets and just say 如果它是python的旧版本,请忘记括号,然后说
print 'n==4'
and 和
print 'done'
This is because in older versions of python (2.7) brackets were not needed for the print statement. 这是因为在旧版本的python(2.7)中,print语句不需要括号。 I see that you are saying it is python3.x, but that is the only thing I can think of;
我看到你说它是python3.x,但这是我唯一能想到的; this code works perfectly for me both in pycharm and in the official IDLE.
这段代码在pycharm和官方IDLE中都适用于我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.