Python 3 latest code crumbs

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

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

yaml json
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!...

f-string trick
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....

list comprehension
Use a Python f-string

Use a Python f-string

Apr 11, 2022 by erik

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

f-string
Return the last element of a Python list

Return the last element of a Python list

Apr 5, 2022 by erik

Finish the function so it returns the last element of the given list. You may assume the list is not empty....

list