Python 3 latest code crumbs

Create an iterable with a constructor

Create an iterable with a constructor

May 24, 2022 by erik

Add a constructor to the EvenNumbers class that accepts a parameter called max. This max comes instead of the hard-coded value of 8. So the iterator must return values until it reaches this max value, but it must include the...

Python pass statement

Python pass statement

May 10, 2022 by erik

Python has a special keyword called pass. The Python pass keyword tells Python to do nothing at all. In other words: just pass this line of code and continue. If you are used to programming in C-like languages, you probably...

Convert JSON to YAML using Python

Convert JSON to YAML using Python

May 6, 2022 by erik

If you need to convert JSON to YAML, you can simply parse the JSON with the built-in JSON library. In the next step, you can use the PyYAML module to convert the object to YAML. In this example, we open...

Quickly print your Python variables with this f-string trick

Quickly print your Python variables with this f-string trick

Apr 20, 2022 by erik

There's an easy way to print the contents of variables by using f-strings. Using this trick, Python prints both the variable name and its value. This is useful for debugging purposes!...

Convert strings to numbers by using a list comprehension

Convert strings to numbers by using a list comprehension

Apr 12, 2022 by erik

Convert the numerical strings in the list numbers into actual numbers (integers) by using a list comprehension. If you need a little guidance, make sure to read my article on list comprehensions first....

Use a Python f-string

Use a Python f-string

Apr 11, 2022 by erik

Use an f-string to complete this challenge....