My Coding Quiz #47

in #hive-19768510 months ago

My Coding Quiz #47 👨‍💻🛠️🧩

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: '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.


Mi Quiz de Programación #47 👨‍💻🛠️🧩

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: '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.

Sort:  

What a coding quiz that engaged! Posts like yours always offer such valuable ideas on programming concepts. Trust me, you have some very great blogs and I will learn more about how to code through them. Keep up the good work!

Thank you

You're welcome Sir.

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

Interesante!

@tipu curate 8

This post has been manually curated by @bhattg from Indiaunited community. Join us on our Discord Server.

Do you know that you can earn a passive income by delegating to @indiaunited. We share more than 100 % of the curation rewards with the delegators in the form of IUC tokens. HP delegators and IUC token holders also get upto 20% additional vote weight.

Here are some handy links for delegations: 100HP, 250HP, 500HP, 1000HP.

image.png

100% of the rewards from this comment goes to the curator for their manual curation efforts. Please encourage the curator @bhattg by upvoting this comment and support the community by voting the posts made by @indiaunited.

Thank you!