+ 1
Please explain.
What is happening on line 7 and 10 ? https://code.sololearn.com/c9jVnA2Ud9D6/?ref=app
6 Respostas
+ 3
s = "ã"
print(s)
You assigned 'ã' to s
s=ascii("ã")
print(s)
It will assign the ascii value of ã to s that is \xe3
ss = str(s)
Here you converted the value to a string
print(type (ss),ss)
The type function prints the datatype of ss that is string or str and it will also print the value as you have ss in print too.
#<class 'str'> '\xe3'
ee = eval(s)
After evaluation the ascii code is converted into ã again so the string is simply assigned to ee
print(type(ee), ee)
Again the type function to print datatype and the value of ee
#<class 'str'> ã
+ 2
Utkarsh Sharma
1. On line 7 why str function is not converting '\xe3' to "ã"❓
2. Since str('\xe3') == 'ã' then why str(s) ! = 'ã' ❓
Please explain.
+ 2
ClassHacker I think it is because of the ascii() function.
When you normally assign
a = '\xe3'
b = str(a)
and do print(b)
The output will be ã as it will read the string '\xe3' as an ascii code.
but if you do
a = ascii('\xe3')
b =str(a)
print(b)
It is no longer taken as an ascii code but a normal string. That's why '\xe3' is printed.
You can wait for a more knowledgeable user to answer this briefly.
+ 1
Coder's Crux So why the outputs are different?
+ 1
ClassHacker The outputs are different because in ss the value assigned is still ascii code but in ee after eval(s) it is again converted into ã. Both are strings but values are different.
0
In lines 7 and 10 it converts to string the type of the objects, and then prints the ascii value of the letter