In many cases, it is convenient to perform mathematical operations on objects rather than numerical values. Python classes have the ability to emulate the behaviour of numeric values to support operations like addition and subtraction. You can override many more to support number-like functionality. Numeric functions In the following table, the right column contains expressions...
Advanced Python: classes String and computed attribute
This article demonstrates more advanced features of Python classes and their customisation. Specifically, how enum objects are created, class to strings, and computed attribute. Class string values A string is typically an informal representation of the object. However, it’s just a nicely in human-readable form. Python provides 2 common methods, i.e. str() and repr(). We can...
Advanced python: collections
In part 2, we introduced advanced python knowledge with built-in functions and other useful tools for sequence iteration, data transformation. Advanced python part 3 will continue with collections to manipulate our data. Named tuple Suppose we want to define a data structure to represent a geometric point on a typical x and y-axis. We could easily do this by defining a regular...
Advanced python part 2
In part 1, we introduced advanced string, bytes manipulation in Python. This article covers some advanced python knowledge with built-in functions and other useful tools for sequence iteration, data transformation. Useful built-in functions Use any() to return true if any of the sequence values are trueUse all() to return true only if all values are trueQuickly find the minimum/maximum value in a...
Advanced python: Styling, Boolean, String and bytes
Let get some more advanced python techniques, tools, libraries. Python coding style It is quite common for beginner to skip the coding style and conventions in any programming language. But when you have a chance to revisit your code or others’ code, you will soon recognise how important of following coding conventions. To learn more, you can visit PEP 8 — Style guide for Python code...