Why doesn't this work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why doesn't this work?

Recently, I copied a character from the internet (supposed to be '\0' I guess) and made this code using that undisplayable character: for a in "ab": print(ord(a)) # Where, a string of that character has been included between 'a' and 'b'. Why does SL show "SyntaxError" whenever I run this code? I had made this code for knowing what exactly that 'undisplayable' character was.

12th Jun 2021, 8:35 AM
Calvin Thomas
Calvin Thomas - avatar
7 Answers
+ 2
Calvin Thomas , the hex editor shows, that there are 46 null characters between a and b. i assume that this is nothing that comes from a regular program, but something that is constructed. using hex editor i was able to do the same thing just by saying insert bytes = 3 value = 00. for all who are interested, here is the link to the editor: https://hexed.it/
12th Jun 2021, 2:50 PM
Lothar
Lothar - avatar
+ 3
Calvin Thomas , if you can please post the code that creates the issue to playground and link it here? that would be great - thanks!
12th Jun 2021, 11:27 AM
Lothar
Lothar - avatar
+ 1
Lothar Here you go: https://code.sololearn.com/caX996cebWqb/?ref=app I'm very sure that it's a null character between a and b that's causing the problem, but the question is why.
12th Jun 2021, 12:38 PM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Lothar Thanks for the link, but why does SL show an error when I try to print strings containing null characters?
12th Jun 2021, 4:52 PM
Calvin Thomas
Calvin Thomas - avatar
0
Runtime Terror Raw strings doesn't seem to make a difference in order for the code to work.
12th Jun 2021, 10:16 AM
Calvin Thomas
Calvin Thomas - avatar
0
Runtime Terror Doing it in C shows that my clipboard actually contains a null character.
12th Jun 2021, 10:20 AM
Calvin Thomas
Calvin Thomas - avatar
- 2
It would work well with while loop instead of for loop. while "a" in "ab": print(ord("a")) break As,in your case a is not defined!
13th Jun 2021, 8:16 AM
Abhinandan Prasad