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: Line 1 simply creates a d list of two numeric elements, while line 2 creates an inline func function that takes a parameter and applies the pop method to it., returning the removed value.
Line 3 introduces the function all, which evaluates a list that, as we will see, is modified at run time. We see that func is called a couple of times, providing the list d as an argument and this is modified, since it is a pass by reference. By the time the value of the third list element on line 3 is evaluated, d will be empty, so it will be considered Falsy. The results that all will evaluate will then be -1, 2 and [].
The all function returns True if and only if all the elements in the given list are Truthy, but in our case that is impossible. Hence the value of r is False and is what is printed on the screen at the end.
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: False. La l铆nea 1 simplemente crea una lista d de dos elementos num茅ricos, mientras que la l铆nea 2 crea una funci贸n inline func que toma un par谩metro y le aplica el m茅todo pop, devolviendo el valor retirado.
La l铆nea 3 introduce la funci贸n all, la cual eval煤a una lista que, como veremos, es modificada en tiempo de ejecuci贸n. Vemos que se llama a func un par de veces, proveyendo la lista d como argumento y esta es modificada, pues es un paso por referencia. Para cuando se eval煤e el valor del tercer elemento de la lista de la linea 3, d estar谩 vac铆a, por lo que se considerar谩 como Falsy (falso). Los resultados que evaluar谩 all ser谩n entonces -1, 2 y [].
La funci贸n all retorna True si y solo si todos los elementos de la lista dada son Truthy (verdaderos), pero en nuestro caso eso es imposible. De all铆 que el valor de r es False y es lo impreso en pantalla al final.
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.