In what variable is the output of print() stored? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

In what variable is the output of print() stored?

consider the code: x=8 print(x+10) obviously, we get a result 18. Since i haven't assigned it to anything, Where is this integer 18 stored?

3rd Jan 2018, 4:12 AM
Muhammed Irfan
Muhammed Irfan - avatar
4 Answers
+ 4
Stored in this file: sys.stdout To access do: import sys to write stuff to it, sys.stdout.write("Str") #same as print("Str")
3rd Jan 2018, 4:36 AM
๐Ÿ‘‘ Prometheus ๐Ÿ‡ธ๐Ÿ‡ฌ
๐Ÿ‘‘ Prometheus ๐Ÿ‡ธ๐Ÿ‡ฌ - avatar
+ 1
Pretty sure it'd be stored in memory. Because print() does the calculations and stuff.
3rd Jan 2018, 4:28 AM
LunarCoffee
LunarCoffee - avatar
+ 1
@Pegasus True, it is stored in sys.stdout. Also, you can just use the file argument of the print builtin to print to the 3 system file streams: import sys print("stderr!", file=sys.stderr)
3rd Jan 2018, 5:00 AM
LunarCoffee
LunarCoffee - avatar
- 1
I know it's stored in memory! I want to know where is it stored. Is there a way I can access it later?
3rd Jan 2018, 4:31 AM
Muhammed Irfan
Muhammed Irfan - avatar