Welcome to the new installment of my series of Coding Quizzes, in which you will be able to test your knowledge and skills about programming and software development in a simple and fun way. If you want to learn more about it visit my blog here on Hive and the first post where I introduced it.
Solution to the previous quiz: AttributeError. Line 1 creates a tuple with 3 elements and names it z.
Line 2 applies the pop method to the tuple and this generates the exception AttributeError: 'tuple' object has no attribute 'pop', which is enough self-explanatory.
Let's remember that tuples are not lists and when encoding we must keep their differences in mind. Since tuples are immutable, there is no point in trying to modify them with the pop method.
As for line 3, it is not executed within the framework of the complete program due to the previous exception.
Now, if z were not a tuple but a list, the program would have been valid and we would have obtained 0b01 as output. I'll leave it to you to figure out why that's the case.
If you want to blog about computer science and programming content, I invite you to join Hive and participate in its communities, such as STEM-social, Develop Spanish, Programming & Dev and others.
Bienvenido a mi nueva serie de Quizzes de Programaci贸n, en la cual podr谩s poner a prueba tus conocimientos y habilidades sobre programaci贸n y desarrollo de software de una manera sencilla y divertida. Si quieres aprender m谩s sobre ella visita mi blog aqu铆 en Hive y el primer post donde la present茅.
Soluci贸n al quiz anterior: AttributeError. La l铆nea 1 crea una tupla con 3 elementos y la llama z.
La l铆nea 2 le aplica el m茅todo pop a la tupla y esto genera la excepci贸n AttributeError: 'tuple' object has no attribute 'pop' (AttributeError: el objeto tupla no tiene el atributo pop), que ya es suficientemente autoexplicativa.
Recordemos que las tuplas no son listas y a la hora de codificar debemos tener presente sus diferencias. Puesto que las tuplas son inmutables, no tiene sentido tratar de modificarlas con el m茅todo pop.
En cuanto a l铆nea 3, no llega a ejecutarse en el marco del programa completo por la excepci贸n previa.
Ahora bien, si z no fuese una tupla sino una lista, el programa habr铆a sido v谩lido y habr铆amos obtenido una como salida 0b01. Te dejo a ti averiguar porqu茅 ese es el caso.
Si quieres bloguear sobre contenido inform谩tico y de programaci贸n, te invito a unirte a Hive y participar en sus comunidades, tales como STEM-social, Develop Spanish, Programming & Dev y otras.