Python Forum

Full Version: Built in Functions not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Basic built in functions like len(),str(),int() and float() do not work in a text.py file but do in IDLE. Does anyone know why and how to fix this. I'm kind of stuck on this until I can move on to the next task.

len("python")
str(100)
int("1")
float(100)

int("110")
int(20.54)

float("16.4")
float(99)

Results in IDLE:

Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
RESTART: C:\Users\mhoneycutt.EMSTEC\AppData\Local\Programs\Python\Python36\test1.py
>>>
Please be more descriptive of the problem.

If what you posted is the contents of text.py, you aren't printing anything. You would need something like

print(int("1"))
as an entry
There is a difference between typing code in the interactive repl (IDLE) or executing a script.
The abbreviation repl stands for Read-Evaluate-Print-Loop.

When entering the code into IDLE, you get always the last Output and additional output which is printed via the print function to stdout.

Executing a Python program does it not. There you have explicit to print the output. Your assumption that a script does the same, is not logical. If a program does this, it's very verbose and useless at the end.
That makes complete sense. I can't believe I didn't realize this. Thanks for the reply.
No problem. Beginners can run into it. Sometimes we forget how it was as we started with programming.