Python Challenge explained | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Python Challenge explained

Kindly, can someone explain this?? Challenge Question: What is the output of this code? s = "SoloLearn" s[0] = "Y" print(s) Choices: Output is SoloLearn Type Error Syntax Error Output is YoloLearn Quiz returns type error is correct.

30th Jun 2021, 6:59 AM
EO4Wellness
EO4Wellness - avatar
2 Respuestas
+ 4
OK firstly, strings in python can be interpreted as immutable lists. So you can access to any symbol of the given string by its corresponding index number. Remember indexing starts from zero. Now, keeping in mind that string is immutable list like tuple, we can conclude that trying to change any item of the IMMUTABLE list will lead to error. to change string we can reassign it or make new one with different variable. Therefore, Yes answer is type Error
30th Jun 2021, 9:29 AM
Shadoff
Shadoff - avatar
+ 1
Shadoff You're right. Sorry for the mistake EO4Wellness. I think I should revisit the python course 😅
30th Jun 2021, 10:21 AM
Baspberry