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: 'eniolw.com '. This riddle script is simple. It all comes down to knowing the built-in lstrip method. Do you know what it does? Well, it removes all the characters you provide as arguments from the string where it is applied, as long as those characters are at the beginning of the string.
As in our code we specified txt.lstrip("@."), both @ and . will be removed from the initial part of the string contained in txt. That string is "@eniolw.com ", so the function removes the @ character, but not the . character, since it cannot be considered to be at the beginning of the string. As a consequence, the given characters that do not satisfy that condition are ignored without raising an exception.
The resulting new string stored in the variable res is "eniolw.com ". Note that the lstrip method does the above, but it does not remove the whitespaces at the beginning and end of the string, as the strip method would do, which is why the whitespace at the end is preserved here. Did you know this or were you tricked?
Frankly, I find the lstrip method unusual, but it may have some applications. It can be useful for removing that @ as we already saw, and it can also remove other prefixes like https://, etc.
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: 'eniolw.com '. Este script de acertijo es simple. Todo se reduce a conocer el m茅todo integrado lstrip. 驴Sabes lo que hace? Bueno, elimina todos los caracteres que proporcionas como argumentos de la cadena donde se aplica, siempre que esos caracteres est茅n al principio de la cadena.
Como en nuestro c贸digo especificamos txt.lstrip("@."), tanto @ como . se eliminar谩n de la primera parte de la cadena contenida en txt. Esa cadena es "@eniolw.com ", por lo que la funci贸n elimina el car谩cter @, pero no el car谩cter ., ya que no se puede considerar que est谩 al principio de la cadena. Como consecuencia, los caracteres dados que no cumplen esa condici贸n se ignoran sin generar una excepci贸n.
La nueva cadena resultante almacenada en la variable res es "eniolw.com ". Ten en cuenta que el m茅todo lstrip hace lo anteriormente dicho, m谩s no elimina los espacios en blanco al principio y al final de la cadena, como lo har铆a el m茅todo strip, raz贸n por la cual el espacio en blanco al final se conserva aqu铆. 驴Sab铆as esto o te dejaste truquear?
Francamente, el m茅todo lstrip me parece inusual, pero puede tener algunas aplicaciones. Puede ser 煤til para eliminar ese @ como ya vimos, y tambi茅n puede eliminar otros prefijos como https://, etc.
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.