What happens when I write print('Something')
?
Does the interpreter work directly with the system I / O means, or does it use some kind of system API, which gives information that something needs to be displayed in the console?
Likewise for input. If I call the input()
function, then it is the python interpreter itself that will read the input values, or it will again delegate this work to some system API, which will wrap the input.
I know that python is written in C language (at least its main implementation). It turns out that it is the C language inside the interpreter that is responsible for the input / output?
All my attempts to find an answer come down to articles where they tell me that in input()
you need to press a button from the keyboard, and the print()
function will print something in the console. I already know this, I want to know what is happening at the level below.
When you write print('Something')
, here's what happens at a lower level:
print('Something')
statement, it first evaluates the expression within the parentheses, which is just a string in this case, 'Something'.Similarly, when you use input()
:
input()
, it pauses
the program's execution and waits for the user to input some text.So, in summary, when you interact with the Python interpreter using functions like print() and input(), the interpreter itself relies on system APIs provided by the operating system to handle the actual input and output operations. This abstraction allows Python to work seamlessly across different platforms and environments.