What's the difference between using print ('Hi') and using string "Hi" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

What's the difference between using print ('Hi') and using string "Hi"

?

14th Aug 2019, 2:29 AM
Guilherme Botelho Augusti
Guilherme Botelho Augusti - avatar
5 Answers
+ 6
whenever you use python console to use verify example codes, then for each line of the code that are entered at each instant, python console responds to that line code, which can be either >>> "Hi" or >>> print("Hi"), here the responds is same for both codes that is Hi, though the reasons behind for those responses are not same. >>> "Hi" in python console responds by outputing Hi that python console received Hi text value at the end of the execution of that line code. In, >>> print("Hi"), python console responds that it is displaying Hi. Now, if we write those two line codes in python script file, and execute that python file in python console, like, Let example.python be the file, and the code content be as follows: "Hi" print("Hi") What output do you see when executing the python scripting file through python console? You will see only one Hi, instead of two Hi. The reason is because while executing through python file, you will see outputs of what the python file code wants display through function like print(), all other intermediate responses that are received by python console are not displayed, which is not the case when you directly enter line codes in the python console, where intermediate responses are default. Let us look at another closely related example from newer perspective. Try this two line of codes directly in python console and also through the python scripting file. And reply. >>> message="Hi" >>> print(message) Hint: look out for the respond for >>> message="Hi" while directly entering in python console... reply your observation....
14th Aug 2019, 10:23 AM
Ve Sudhakaran
+ 3
Each string and character is stored in memory in a different way. But as a result, it can be the same.
14th Aug 2019, 2:35 AM
Coder
Coder - avatar
+ 2
there's no difference between "hi" & 'hi' in python.but in c++ for example we use " " for strings & we use ' ' for chars.
15th Aug 2019, 3:47 AM
hamidreza
+ 1
The python interpreter's output will be: Hi for the print('Hi') without quote And 'Hi' for just the "Hi" with quote The difference... is that you made use of the function (print)....
15th Aug 2019, 5:56 PM
Jaekeys
Jaekeys - avatar
- 1
same thing
14th Aug 2019, 7:36 AM
Rateb Khawandi
Rateb Khawandi - avatar