Python Forum
Return Statement in Python IDLE editor - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Return Statement in Python IDLE editor (/thread-3957.html)

Pages: 1 2


Return Statement in Python IDLE editor - NMW - Jul-11-2017

Hi, I'm somewhat of a programming "newbie" , so bear with me.

I have been practising with Python (2) through Python IDLE. However, when I type code in the editor window and utilize a return statement, the return statement doesn't work after I run the code (there's no output in the shell window). Normally I would be able to type my code in the editor window, run it,and then get the results in the shell window.

However, when I type that same code in the shell window, and run the code, the return statement does work. How do I solve this? I want to be able to just type my code in editor mode, and then run.


def compare(x,y):
       if x > y:
               return 1
       if x == y:
               return 0
       if x < y:
               return -1

compare(5,7)



RE: Return Statement in Python IDLE editor - Larz60+ - Jul-11-2017

Idle is not the best editor, it has some quirks.
You'd be much better off choosing another editor.
Though choice of an IDE is a personal preference, I use and like PyCharm (community edition)
Others on this site praise atom editor


RE: Return Statement in Python IDLE editor - NMW - Jul-11-2017

(Jul-11-2017, 07:32 PM)Larz60+ Wrote: Idle is not the best editor, it has some quirks.
You'd be much better off choosing another editor.
Though choice of an IDE is a personal preference, I use and like PyCharm (community edition)
Others on this site praise atom editor

Thanks, I'll try PyCharm..:-)


RE: Return Statement in Python IDLE editor - snippsat - Jul-11-2017

In IDLE(file code window(run F5) or other editors you need to print() to get the result.
REPL interactive interpreter(>>>) dos not need print().
>>> a = 'hello'
>>> a
'hello'
As code to run.
a = 'hello'
print(a)
Use 4-space indentation.
IPython or ptpython in combination with cmder,
you get much better REPL and nice colors that cmd dos not have.
[Image: vrwOsD.jpg]


RE: Return Statement in Python IDLE editor - NMW - Jul-11-2017

(Jul-11-2017, 08:14 PM)snippsat Wrote: In IDLE(file code window(run F5) or other editors you need to print() to get the result.
REPL interactive interpreter(>>>) dos not need print().

Thanks, I did indeed download and install Pycharm like the other member suggested, but no luck using that either. So I guess I'll just have to use the interpreter/shell mode to see the results of my return statement.

By the way, is there any Python GUI that allows you to run part of the code by either selecting the part you want to run and then choosing run selection or something?


RE: Return Statement in Python IDLE editor - sparkz_alot - Jul-11-2017

(Jul-11-2017, 06:44 PM)NMW Wrote: Hi, I'm somewhat of a programming "newbie"

As a "newbie" you should really be using the most recent version of Python, currently 3.6.1 (due to be updated to 3.6.2 on 17 July 2017) unless you absolutely need to use version 2


RE: Return Statement in Python IDLE editor - snippsat - Jul-11-2017

Quote:Thanks, I did indeed download and install Pycharm like the other member suggested, but no luck using that either. So I guess I'll just have to use the interpreter/shell mode to see the results of my return statement.
Did you understand the part with print()?
You download PyCharm community edition(free).
[Image: JspzSU.jpg]
Quote:By the way, is there any Python GUI that allows you to run part of the code by either selecting the part you want to run and then choosing run selection or something?
Yes, an PyCharm has a couple of ways,when i use it sometimes(i use Atom).
I use mark code --> right click --> Execute selection in console.
The get output and can continue to test.
If mark all code i get -1,but can continue to to test.
-1
>>> compare(7, 4)
1
>>> compare(7, 7)
0
PyCharm is good for beginner because you get all tool out of the box(use basic tool to run code in the beginning).


RE: Return Statement in Python IDLE editor - NMW - Jul-11-2017

(Jul-11-2017, 09:21 PM)sparkz_alot Wrote:
(Jul-11-2017, 06:44 PM)NMW Wrote: Hi, I'm somewhat of a programming "newbie"

As a "newbie" you should really be using the most recent version of Python, currently 3.6.1 (due to be updated to 3.6.2 on 17 July 2017) unless you absolutely need to use version 2

I don't know, isn't there some kind of age old discussion as to which Python version (2 or 3) you should use if you want to learn Python? And "experts" have stated that if you're in the learning stages you should use Python 2 ?
and I quote :
Quote:“Python 3 is a nicer and more consistent language, BUT, there is very limited third-party module support for it. This is likely to be true for at least a couple of years more. So, all major frameworks still run on Python 2, and will continue to do so for a significant time. Therefore, if you learn Python today, you should learn Python 2, because that is the version you are going to end up actually using.”
source:http://learntocodewith.me/programming/python/python-2-vs-python-3/

That's why I'm using Python 2, I guess...

Quote:Did you understand the part with print()?

Yes I did, I could adapt my code or I could just use the interpreter. Both would work, I guess. I was afraid that my code was wrong, but now I know it's probably just some sort of "glitch"...

(Jul-11-2017, 09:30 PM)snippsat Wrote:
Quote:Yes, an PyCharm has a couple of ways,when i use it sometimes(i use Atom).

Quote:PyCharm is good for beginner because you get all tool out of the box(use basic tool to run code in the beginning).

Thanks, I'll use PyCharm for my next Python tutorials... :-)


RE: Return Statement in Python IDLE editor - snippsat - Jul-11-2017

(Jul-11-2017, 09:31 PM)NMW Wrote: source:http://learntocodewith.me/programming/python/python-2-vs-python-3/
That's from 2014 and do not make sense now.
All beginners should learn Python 3,and start with Python 3.6(install tutorial)
If you look further down the post.
Quote:The StackOverflow discussion posted above has been updated
to reflect that one SHOULD start with Python 3 if they are learning today, in 2015.



RE: Return Statement in Python IDLE editor - Larz60+ - Jul-11-2017

Just an FYI
Quote:but no luck using that either
this in pycharm:
def compare(x, y):
   if x > y:
       return 1
   if x == y:
       return 0
   if x < y:
       return -1
print(compare(5, 7))
Output:
-1 Process finished with exit code 0