Search code examples
python-3.xpython-idle

Typing text into IDLE


I usually use Pycharm where running a scratch with just "One more question ' + ' down." would evaluate to blank.

However "One more question ' + ' down." in IDLE evaluates to "One more question ' + ' down."

Can someone please explain why?


Solution

  • I think I understand your question:

    I think you are getting confused between the IDLE shell and the 'file editor' in PyCharm. When you open up IDLE, it will have a prompt where you type in a Python statement that looks like this:

    >>>
    

    You can type your command in there, and press enter to have it execute immediately. I think that you've done this and it looks like this:

    >>> "One more question ' + ' down."
    "One more question ' + ' down."
    

    It outputs the exact same thing. However, if you had a file in PyCharm that just contained the line "One more question ' + ' down." and you ran it, nothing would happen. I think you are wondering why this is.

    It is because, the IDLE shell is not for writing proper programs, and it automatically outputs whatever the expression you put into it evaluates to. In a 'real' python program, you need to use print() to output things to the console. From within IDLE, you'll want to go to File > New File to get to the proper editor which is the equivalent of what PyCharm does.

    For instance, running print("One more question ' + ' down.") from withing PyCharm will output "One more question ' + ' down." when you run it.

    I hope this answers your question!