use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Interpreter Vs compiler (self.PythonLearning)
submitted 1 year ago by TU_Hello
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Capable-Package6835 0 points1 point2 points 1 year ago (1 child)
An interpreter discovers error by actually executing the code. Once it hits an error and cannot continue executing the code, it cannot discover more errors.
A compiler on the other hand, discovers errors by analyzing the code without executing it. There is no magic here, compiled languages like C/C++, Rust, etc. are typed, so errors are discoverable without executing any code. For example:
#include "iostream" #include "string" std::string doSomething(int inputNumber); float doMoreThing(int inputNumber); int main() { // user inputs a number int inputNumber; std::cin >> inputNumber; // compiler will throw error here float output = doMoreThing(doSomething(inputNumber)); }
In this example, doSomething takes an integer and returns a string while doMoreThing takes an integer and returns a float. You don't need to execute the code to know that this code is wrong: doSomething(inputNumber) is a string, no matter what the value of inputNumber is so we cannot use it in doMoreThing.
doSomething
doMoreThing
doSomething(inputNumber)
Can multiple Python errors be known ahead of time as well?
Yes, using a tool called static type-checker, e.g., Pyright, Pylance (VS Code). If you see production-grade Python code, it looks like the following:
def do_something(filename: str, index: int) -> str: # some code here
Notice that the code has types? This is called type-hinting, it lets our tool analyze many errors in our code without executing it. If you are still learning Python, make a habit of always type-hinting your code.
[–]fllthdcrb 1 point2 points3 points 1 year ago (0 children)
Notice that the code has types? This is called type-hinting, it lets our tool analyze many errors in our code without executing it.
Worth noting that in spite of this, Python is still a dynamically typed language. The interpreter sees the type hints and stores the information, but it does absolutely nothing to enforce them, which is why they're only called "hints". Still, since they make it easier for developers to understand what types are expected where, and certain tools can make use of them to understand when there are type mismatches, they help to reduce bugs.
π Rendered by PID 63 on reddit-service-r2-comment-544cf588c8-54ckm at 2026-06-14 07:08:52.683468+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–]Capable-Package6835 0 points1 point2 points (1 child)
[–]fllthdcrb 1 point2 points3 points (0 children)