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: Science Tech Engineering Math. Line 1 creates the string p = "science,tech,engineering,math" on which the operations will be performed.
Line 2 splits the string into a list using the well-known split method. Since the argument is ",", w will consist of ['science', 'tech', 'engineering', 'math']. Then we modify the last element of w by making it capital letters with upper, so that w becomes ['science', 'tech ', 'engineering', 'MATH'].
Then, we apply join to obtain a new string based on the list w and specifying a blank character separator, thus obtaining 'science tech engineering MATH' which is the value of n.
Finally we print n.title(). What this curious method does is make the first letter of each word capital and the rest lower case, as in a heading. Hence we get Science Tech Engineering Math at the end.
These split and join operations are extremely common when programming in Python. The title method, for its part, is not so common, but it can be very useful.
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: Science Tech Engineering Math. La l铆nea 1 crea el string p = "science,tech,engineering,math" sobre el cual se operar谩.
La l铆nea 2 descompone el string en una lista usando el conocido m茅todo split. Como el argumento es ",", w consistir谩 en ['science', 'tech', 'engineering', 'math']. Luego modificamos el 煤ltimo elemento de w haciendolo letras may煤sculas con upper, con lo cual w queda en ['science', 'tech', 'engineering', 'MATH'].
Luego, aplicamos join para obtener un nuevo string con base en la lista w y especificando un separador de caracter en blanco, obteniendo as铆 'science tech engineering MATH' que es el valor de n.
Finalmente imprimimos n.title(). Este curioso m茅todo lo que hace es hacer que la primera letra de cada palabra sea may煤scula y las dem谩s min煤sculas, como en un encabezado. De all铆 que obtengamos Science Tech Engineering Math al final.
Estas operaciones con split y join son extremadamente comunes cuando se programa en Python. El m茅todo title por su parte no es tan comun, pero si puede ser muy 煤til.
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.