print('He\'s a coder') the output is He's a coder. and when I'm using ("He's a coder") the output is same in Sololearn playgroun | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

print('He\'s a coder') the output is He's a coder. and when I'm using ("He's a coder") the output is same in Sololearn playgroun

Does the same thing happen in Python 3 IDE ? Or it shows the output like 'He's a coder' and "He's a coder" ??? Plus does we need to use print statement in again and again in Python 3 IDE to get all the output ??

25th Jul 2017, 11:54 AM
Ramesh
Ramesh - avatar
6 Answers
+ 5
When you want to say to Python: hey take this sentence and put it inside this variable, you write the name of variable, an equal sign to say you want assign a value to it, and give the sentence embeded in 'quotes' (double or simple, to specify start and end of a 'string' type value): myvar = "forty-two" Well, Python do the same when he output a value in the CLI environement without you explicitly call the 'print()' function: enclosing string value inside quotes... (I don't have simplest words ;P)
26th Jul 2017, 3:41 AM
visph
visph - avatar
+ 2
So you are using single quotes in the first example that's why you're using the \ (forward slash) In the second example you're using double quotes. If you type in your second example "\"He's a coder\"" you'll find the output to be "He's a coder" So it's all about the type of quotes you're using
25th Jul 2017, 1:03 PM
Limitless
Limitless - avatar
+ 2
If you use Python CLI (Command Line Interpreter -- usualy prompt is '>>>'), you can avoid using print() (it's no more a statement since Python3) function to output most of the time, as CLI output automaticaly returned value of command executed... so simply put a variable name (or a function call) is enough to output its (returned) value: >>> a = 5 5 # outputed as value of a returned by assignement expression >>> a 5 # outputed as value of a (which is kind of expression) But anyway, when you write script, you usualy write it in a text file (in a simple editor or an IDE -- Integrated Development Editor -- which is an advanced text editor specialized in programing languages) to be able to save and reuse it ^^ This file is ran by executing the Python interpreter, which output only what you explicitly program to be outputed by print() function ^^
25th Jul 2017, 1:26 PM
visph
visph - avatar
+ 2
This happen because the output is implicit, so Python show you the type of variable: a string is quoted, as if you was witting a string litteral...
26th Jul 2017, 3:06 AM
visph
visph - avatar
0
but in Python 3. when I write say >>>'This is a string' the output comes in double quotes and when I use >>>"This is a string" the output comes in single quotes. why this happens ??
25th Jul 2017, 2:56 PM
Ramesh
Ramesh - avatar
0
can you explain in an easy language ??
26th Jul 2017, 3:19 AM
Ramesh
Ramesh - avatar