+ 11
Why does this code display "no output" ?
14 Respuestas
+ 8
Python doesn't ignore spaces. The actual output of your code would be a single space. It's just that if the output of your code is "invisible" (like a space), Sololearn displays the message "No output" to let you know that your program has finished (and there's no visible output), so that you don't keep waiting for half an hour
+ 9
Ayan [I'm Also Inside Of Exams] I know the code didn't work because of the extra space between "hello" and "world"...but my question is...so does python ignore upto one space between strings?
+ 8
Anna Thanks, that clarified my doubt!
+ 8
Lothar Did you try the code in sololearn?
+ 8
Lothar That's great, you tested the code on various devices. But whenever I run this code in sololearn from my android device, the output is same : No output.
Maybe the output varies according to various devices and environments. 😊👍
Oh, and by the way, when I run the code on windows 7 Spyder(Python 3.7), it doesn't show any output,I.e., it displays blank space.Also, I have noticed that python ignores upto one space.
If I run print(str[8]) for the above code, the output is o, but it should have been w if the spaces are counted.
I guess the 'no output ' rule is for sololearn only.
+ 6
I think because it's just printing a space, sololearn doesn't want you to get confused that you are printing "nothing". That, or it's a pythin thing, not sure.
if you do print(str[6:]) or any other print with other letters involved, it works fine.
+ 6
Yes it's interesting how white space is considered to be "No output" by Code playground, probably for the reasons mentioned by Anna.
+ 5
https://code.sololearn.com/cpM3Bj1w0aVC/?ref=app
Very interesting 🤔
+ 5
I did some tests again now on various devices. The behaviour is always the same:
- "No output" is only shown if no print() function is called
- As soon as you envoke print function like this: print() the message does not appear also not if you print "spaces". This does not work and creates the message:
while 1==2:
print("hello")
Reason is that this part of programm never will be executed.
test devices: iPhone with pythonista and solo app, iPad with pythonista and solo app, windows 7 with thonny, raspberry pi3 with debian and thonny, SoloLearn website with playground.
+ 4
Maybe ?!!
+ 3
when i try this code on my device it 'shows' the 'invisible space'. But it does NOT say anything like 'No output'. Are you sure it should - Anna?
+ 3
Yes, my try was in SoloLearn on an iOS device. And same result on a local python environment, also on iOS.
+ 1
python count spaces because anything inside string quote everything is string and indexs are start counting from 0 and goes like this 0123456789.
print(str[7]) is w.
For sololearn playground whitespace are considerd empty char by default and empty char are set to 'no output' as default.
- 1
visit my YouTube channel gyankeeda academy for more information