Want to play some music πΆπ΅ in #Python? Check out the 3rd-party VLC package!
Posts by
How to get the absolute value of a number + a BONUS how to get the magnitude of a complex number in #Python using the built-in `abs()` function
Need to convert RGB ro HSV or vice-versa in #Python? Try the colorsys module!
What is the fastest way to create an empty dictionary in #Python? Using `timeit` to find out:
How to change the compression of a JPEG image during saving with #Python and Pillow using only THREE lines of code! ππΌ
A silly example of using a #Python lambda and `filter()` to find multiples of four
How to use borb to create a simple PDF with #Python
How to get information from the user on the command line with #Python using the built-in `input()` function:
How to use #Python's `textwrap` to control multi-line string wrapping ππ₯
#Python includes a handy built-in function called `exec()` that can execute arbitrary code
Never expose your APIs to this or the related `eval()` function since that could allow people to harm your computer!
How to combine two iterables quickly in #Python using the `zip()` function:
What do you use #Python's walrus operator for? πβ
Here's a popular example of its usage:
Have you used #Python's `divmod()` function before?
If not, `divmod()` takes two numbers as arguments and returns a tuple containing their quotient and remainder in a single operation
Need a random number in #Python? Try the `random` module!
I hope you enjoyed learning about #Python string formatting using the `format()` method
Be sure to follow me for more Python tips and tricks! ππ₯
The `format()` method also allows you to set the string alignment.
Here are a few examples:
If you put integers within the curly braces, then you can control which argument goes where (although this is probably the most confusing way to do it)
You can also just use named parameters and skip the dictionary:
You can also use a #Python dictionary when using the `format()` method to use named parameters:
What happens when you have too many braces, though?
Well, you get an error! πβ
When you use `format()`, you still use curly braces in your string. Then you pass in the same number of arguments as you have braces:
Before #Python f-strings, you had to call format()
Sometimes you still do, so it's good to learn about it!
Check out this mini thread on the topic
ππ§΅π
Did you know you can create your own custom iterators in #Python?
All you need to do is write your own custom `__iter__` and `__next__` methods
Here's an example:
I have started posting #Python Pop Quizzes in my newsletter and on my blog @mousevspython πβ
These quizzes include the answers too!
#Python lambda craziness ππ€ͺ
It's lambdas all the way down!
How to check if a string is printable or not in #Python ππ€―