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: ('coding ', 'is', ' fun'). Line 1 defines a seemingly meaningless string a. Line 2 reverses this using the familiar slice notation, creating a new string b. Its content will be 'coding is fun'.
Line 3 applies the partition method which is less known, although somewhat similar to split. What it does is look for the string given as an argument and return a three-element tuple. If there is an occurrence, the tuple will be formed by: 1) what is before the first occurrence, 2) the first occurrence and 3) what is after the first occurrence.
In the case of the string b, since the string "is" was specified to the partition method applied to the string 'coding is fun ', this will return the tuple ('coding ', 'is', ' fun'). Note that white spaces are preserved, as they are valid characters.
The enthusiast @splash-of-angs63 solved this test satisfactorily.
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: ('coding ', 'is', ' fun'). La l铆nea 1 define un string a aparentemente sin sentido. La l铆nea 2 lo invierte usando la conocida notaci贸n de rebanada, creando un nuevo string b. Su contenido ser谩 'coding is fun'.
La l铆nea 3 le aplica el m茅todo partition que es menos conocido, aunque algo similar a split. Lo que hace es buscar la cadena dada como argumento y devolver una tupla de tres elementos. En caso de haber una ocurrencia, la tupla estar谩 formada por: 1) lo que est茅 antes de la primera ocurrencia, 2) la primera ocurrencia y 3) lo que est茅 tras la primera ocurrencia.
En el caso del string b, dado que se especific贸 la cadena "is" al m茅todo partition aplicado al string 'coding is fun', este regresar谩 la tupla ('coding ', 'is', ' fun'). N贸tese que los espacios en blanco se preservan, pues son caracteres v谩lidos.
El entusiasta @splash-of-angs63 resolvi贸 este test satisfactoriamente.
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.