+ 11
21st Jun 2019, 5:00 AM
SWETA X
SWETA X - avatar
14 Respostas
+ 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
21st Jun 2019, 5:57 AM
Anna
Anna - avatar
+ 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?
21st Jun 2019, 5:12 AM
SWETA X
SWETA X - avatar
+ 8
Anna Thanks, that clarified my doubt!
21st Jun 2019, 6:10 AM
SWETA X
SWETA X - avatar
+ 8
Lothar Did you try the code in sololearn?
21st Jun 2019, 6:29 AM
SWETA X
SWETA X - avatar
+ 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.
21st Jun 2019, 12:01 PM
SWETA X
SWETA X - avatar
+ 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.
21st Jun 2019, 5:11 AM
Jackson O’Donnell
+ 6
Yes it's interesting how white space is considered to be "No output" by Code playground, probably for the reasons mentioned by Anna.
21st Jun 2019, 10:52 AM
Sonic
Sonic - avatar
21st Jun 2019, 5:08 AM
Ayan Fox
Ayan Fox - avatar
+ 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.
21st Jun 2019, 11:40 AM
Lothar
Lothar - avatar
+ 4
Maybe ?!!
21st Jun 2019, 5:17 AM
Ayan Fox
Ayan Fox - avatar
+ 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?
21st Jun 2019, 6:28 AM
Lothar
Lothar - avatar
+ 3
Yes, my try was in SoloLearn on an iOS device. And same result on a local python environment, also on iOS.
21st Jun 2019, 8:54 AM
Lothar
Lothar - avatar
+ 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.
21st Jun 2019, 2:21 PM
Danielov
Danielov - avatar
- 1
visit my YouTube channel gyankeeda academy for more information
29th Jun 2019, 3:10 PM
Omkar Shirke(Incognito)
Omkar Shirke(Incognito) - avatar