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:
2. Get a counter when looping through a sequence:
3. Check if a condition holds true for any or all items in a sequence:
4. Print things:
5. Summing values:
6. Uniquify a list:
7. Reverse a list:
8. Make a range of integers with a step:
9. Get a quotient and remainder, for example to divide seconds into minutes + seconds:
10. Name and apply a slice:
11. Use dir() together with a list comprehension to only list "public" methods (and attributes) of an object:
12. Get the min and max of a sequence:
13. Get user input:
14. Check for, get and set attributes:
15. Call a method on the parent class:
16. Use next() to retrieve the next value from a generator:
17. Make values absolute:
18. Sort values, by key, reversed, and in-place:
19. Round numbers:
20. See the representation / string of an object:
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.
Software Engineer| Test Automation Engineer| QA ?? #python #fastapi #django ?? #playwright #pytest #cypress
2 年Mukhtar B. Abdulrazaq