0

In Python 3:

>>> str="Hello" # declare a string str
>>> print(str)
Hello
>>> str
'Hello'

When I don't use print to print the string and simply write >>> str then the output comes in single quotes and when I use >>> print(str) the output does not come in single quotes. So why does this happen?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 1
    Possible duplicate of [In Python interpreter, return without " ' "](https://stackoverflow.com/questions/1482649/in-python-interpreter-return-without) – jonrsharpe Aug 27 '17 at 09:52

2 Answers2

1

In Python interactive shell:
If you declare a variable, then when you type the name of that variable, Python interactive shell will return the value of it. Because there are many data types, if you declare a string, and then call it, Python interactive shell will display it with quotes around, so that you can know it is a string

>>> str = "Hello"
>>> str
'Hello'

If you use the print() function to print the string out, then the string is being "printed". No quotes. Nothing more, nothing less.

First Last
  • 200
  • 3
  • 11
0

When you simply write >>>str you are calling that variable, so the single quotes help to denote that it is a string, but using the print() function it prints the contents of str to the IDLE. Hope this helps :)

chngzm
  • 608
  • 4
  • 13