20 cool things you can do with Python's built-in functions

20 cool things you can do with Python's built-in functions

The Python built-in functions are amazing, they make for clean, fast and concise code. Here are 20 cool things you can do with them:

1. Make a dictionary from two lists:

No alt text provided for this image

2. Get a counter when looping through a sequence:

No alt text provided for this image

3. Check if a condition holds true for any or all items in a sequence:

No alt text provided for this image

4. Print things:

No alt text provided for this image

5. Summing values:

No alt text provided for this image

6. Uniquify a list:

No alt text provided for this image

7. Reverse a list:

No alt text provided for this image

8. Make a range of integers with a step:

No alt text provided for this image

9. Get a quotient and remainder, for example to divide seconds into minutes + seconds:

No alt text provided for this image

10. Name and apply a slice:

No alt text provided for this image

11. Use dir() together with a list comprehension to only list "public" methods (and attributes) of an object:

No alt text provided for this image

12. Get the min and max of a sequence:

No alt text provided for this image

13. Get user input:

No alt text provided for this image

14. Check for, get and set attributes:

No alt text provided for this image

15. Call a method on the parent class:

No alt text provided for this image

16. Use next() to retrieve the next value from a generator:

No alt text provided for this image

17. Make values absolute:

No alt text provided for this image

18. Sort values, by key, reversed, and in-place:

No alt text provided for this image

19. Round numbers:

No alt text provided for this image

20. See the representation / string of an object:

No alt text provided for this image

That's it, 20 snippets of useful things you can do with Python's built-in functions.

Check out the Python Built-in Functions docs for more information.

We also have a related Pybites training on our YouTube channel.

Hope this is helpful and let me know what other Python topics you'd like to know more about ...

- Bob

Ps. the images were created with carbon, I made this tool to make it easier to automatically create those images from the command line.


Freud A.

Software Engineer| Test Automation Engineer| QA ?? #python #fastapi #django ?? #playwright #pytest #cypress

2 年

要查看或添加评论,请登录

Bob Belderbos的更多文章

其他会员也浏览了