+ 15

Please tell why we are getting this output??

https://code.sololearn.com/cGb4h7g3jcCt/?ref=app

16th Jun 2020, 4:48 PM
ANJALI SAHU
35 odpowiedzi
+ 7
If you write a = '25\\24', you get the result you probably expect. I have no idea what exactly is happening if you don't though. Is the second half of the string read as some sort of strange escape sequence? ๐Ÿค”
16th Jun 2020, 4:57 PM
HonFu
HonFu - avatar
+ 5
RAJESH SAHU Try this a="25\\24"
16th Jun 2020, 6:30 PM
NARESH KUMAR
NARESH KUMAR - avatar
+ 5
george yeah you are correct
16th Jun 2020, 6:30 PM
NARESH KUMAR
NARESH KUMAR - avatar
+ 5
Hint: When a question ends up in hot today and has more than 30 answers, probably your answer has already been given. ๐Ÿ˜‰ https://code.sololearn.com/cMBvMY2UD8MB/?ref=app
18th Jun 2020, 10:55 AM
HonFu
HonFu - avatar
+ 4
\x14 is the byte representation of 20 in decimal or 24 in octal. \24 to the str.split() is octal representation as str.split() does not use the STDOUT buffer. Instead it tries to give you a character. Since the character with value 14 hex is not in the character space. It encodes the raw byte value to the string. P. S. \nn or \nnn where n is any digit is octal representation on number in Python.
16th Jun 2020, 5:54 PM
Anubhav Mattoo
Anubhav Mattoo - avatar
+ 3
A backslash is an escape sequence in ASCII. UTF-8 is backwards compatible to ASCII and the output buffer of STDOUT of Python reads any sequence after backslash as an escape sequence. By using '\24' you are giving the STDOUT buffer to use escape sequence 24 (which you should find documented with ASCII Standards). As mentioned by HonFu using '\\' will resolve the error as that is the escape sequence of backslash character.
16th Jun 2020, 5:33 PM
Anubhav Mattoo
Anubhav Mattoo - avatar
+ 3
Octal 24 = Binary 10100 Binary 00010100 = 14 Hex
16th Jun 2020, 6:10 PM
Anubhav Mattoo
Anubhav Mattoo - avatar
+ 2
๐๐–—๐–Ž๐–“๐–ˆ๐–Š๐Ÿค˜[๐ˆ๐–“๐–†๐–ˆ๐–™๐–Ž๐–›๐–Š], he's asking about that very specific strange output he gets in the code. Most generic explanations don't seem to touch this.
16th Jun 2020, 5:06 PM
HonFu
HonFu - avatar
+ 2
\24 means octal value in python
17th Jun 2020, 8:26 PM
Gourav Shimli
Gourav Shimli - avatar
+ 2
RAJESH SAHU \x14 is the byte representation of 20 in decimal or 24 in octal. \24 to the str.split() is octal representation as str.split() does not use the STDOUT buffer. Instead it tries to give you a character when your specified attribute is not found in the given string. Since the character with value 14 hex is not in the character space. It encodes the raw byte value to the string. So to get the result you are expecting i recomend you reqrite your code like this: a="25\24" print(a) b=a.split("\") print(b) There when you remove the other backslash in the string method. It will take that backslash as reference if i can say and rerturns values that are dividded by the backslash. Thus your output will be: b = ['25', '24']
18th Jun 2020, 10:52 AM
Josaphat NGOGA UWIZEYE
Josaphat NGOGA UWIZEYE - avatar
+ 1
RAJESH SAHU problem in 25\24. you need to write 25\\24 to get real 25 and 24 symbols. in your case \24 system recognize \2 as some spec symbol and 5 other sumbol
16th Jun 2020, 5:53 PM
george
george - avatar
+ 1
if you want to use symbol \ as literal you need to \\ , since \ is spec symbol. this is same manner if tou nedd youse โ€œ or โ€˜ symbols as literals โ€œ lalala\โ€โ€
16th Jun 2020, 5:54 PM
george
george - avatar
+ 1
Thanks Everyone๐Ÿ™‚
17th Jun 2020, 6:54 AM
ANJALI SAHU
+ 1
AJ Anant Ooh. aisa kya kiya tha usne??
17th Jun 2020, 2:32 PM
Tronix
Tronix - avatar
+ 1
'a' needs a second backslash too :)
18th Jun 2020, 10:46 AM
Kushan Sharma
Kushan Sharma - avatar
+ 1
RAJESH SAHU The Reason is Tgat In Python When You Want To add a Back_Slash to a string you can't add it juat like that "\" it's because the back slash is used to add symbol and many things some of them you may not find in your keyboard i think The best ex. i can offer is.. When You Need to add a double quote and a single quote to the same string you'll have to use the back slash for example print('There\'s a new car in the street it\'s the first time i see it here') the single quote in the beginning and the end are used declare the string and the quotes between them that follow the backslash are part of the string i hope i helped and sorry if i messed up somewhere my English isn't that strong๐Ÿ˜…๐Ÿ˜›
10th Jul 2020, 3:16 PM
Rateb Sa
16th Jun 2020, 5:39 PM
SOUMYA
SOUMYA - avatar
0
Thanks for your explanation everyone..but I have a doubt when I wrote a="25\24" b=a.split("\\") print(b) I thought "b" will be ["25","24"] But output came as ["25\x14"].. please tell what is the reason for the output...
16th Jun 2020, 5:43 PM
ANJALI SAHU
0
Anubhav Mattoo can you please tell how to convert oct \24 to \x14 I am not getting how it is?
16th Jun 2020, 6:08 PM
SOUMYA
SOUMYA - avatar