My Coding Quiz #31

My Coding Quiz #31 馃懆鈥嶐煉火煕狅笍馃З

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.

Without further ado, here's the riddle...




Quiz
By @eniolw


What's your choice?

Solution to the previous quiz: <class 're.Match'>. We start by importing the re module which is used to work with regular expressions. Then we create a string u representing a URL.

Line 3 contains the heart of the matter: it uses the search function of the re module to search for a / character in the given string u. Since that character does exist, the function will return an object of the re.Match class.

You may wonder why from the class re.Match if the re.search function was used but not the re.match function, shouldn't it be an object of the class re.Search? Well, this class does not exist. The re.Match class was defined to represent these searches and in fact it has a number of useful and powerful methods and properties, such as group and span.

Also, it is important to keep in mind that the operation does not return a list or a tuple, since a search of all matches was not performed; that would be what the re.findall function would return, i.e., a list with all matches. Instead, re.search only looks for the first match and that's it.

Although we do not need to know the type of the object returned by re.search, knowing it demonstrates an advanced mastery of the language and even knowing without hesitation that it does not return a list or a tuple is definitely a basic knowledge that we should have.


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.


Mi Quiz de Programaci贸n #31 馃懆鈥嶐煉火煕狅笍馃З

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茅.

Sin m谩s pre谩mbulos, he aqu铆 el acertijo...




Quiz
Por @eniolw


驴Cu谩l es tu elecci贸n?

Soluci贸n al quiz anterior: <class 're.Match'>. Comenzamos importando el m贸dulo re que se utiliza para trabajar con expresiones regulares. Luego creamos una cadena u que representa una URL.

La l铆nea 3 contiene el meollo del asunto: utiliza la funci贸n search del m贸dulo re para buscar un car谩cter / en el cadena dada u. Como ese car谩cter existe, la funci贸n devolver谩 un objeto de la clase re.Match.

Te preguntar谩s por qu茅 desde la clase re.Match si se us贸 la funci贸n re.search pero no la funci贸n re.match, 驴No deber铆a ser un objeto de la clase re.Search? Bueno, esta clase no existe. La clase re.Match se defini贸 para representar estas b煤squedas y, de hecho, tiene varios m茅todos y propiedades 煤tiles y potentes, como group y span.

Adem谩s, es importante tener en cuenta que la operaci贸n no devuelve una lista o una tupla, ya que no se realiz贸 una b煤squeda de todas las coincidencias; eso ser铆a lo que devolver铆a la funci贸n re.findall, es decir, una lista con todas las coincidencias. En cambio, re.search s贸lo busca la primera coincidencia y listo.

Aunque no necesitamos saber el tipo de objeto devuelto por re.search, saberlo demuestra un dominio avanzado del lenguaje e incluso saber sin dudarlo que no devuelve una lista o una tupla es definitivamente un conocimiento b谩sico que deber铆amos tener.


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.

H2
H3
H4
3 columns
2 columns
1 column
7 Comments