my_variable_name = str("John")
print(my_variable_name)
This is the code for example, now if I happen to add the double quotes around "my_variable_name" in this statement:
print(my_variable_name)
It just simply display whatever is written inside the "" but if I don't add it'll print "john". Now what I think the reason is because when compiler find something inside "" that tells it to display whatever datatype it is while without "" it just displays the stored or u can say assigned value . I know its easy (basis) but I do this like all the time and my knowledge about this problem never satisfies me
The problem has nothing to do with print function.
"my_variable_name"
is a string literal. Single or triple quotes could also be used.
my_variable_name
is a reference to a previously defined variable of that name. The type of the variable's value could be anything.
You can print any object, and it'll return the str()
representation of it.
Unrelated, you don't need str()
function to define a string literal.
when compiler find something inside "" that tells it to display whatever datatype it is
Python is an interpreted language, it's not the compiler doing this. The datatype of anything enclosed in quotes is always a string