Day: May 13, 2021

Python Built-in Methods – Python chr() Function

Python chr() Function Returns the Unicode character Usage The chr() function returns the character that represents the specified number (unicode code point). The valid range for the number is from 0 to 1,114,111 (0x10FFFF). ValueError will be raised if you specify number outside that range. You can convert it back to unicode using the ord() function. Syntax chr(number) Parameter Condition Description number Required An …

Python Built-in Methods – Python bin() Function

Python bin() Function Convert an integer number to a binary string Usage The bin() function converts an integer number to a binary string. The result will always be prefixed with ‘0b’. Syntax bin(number) Parameter Condition Description number Required Any integer Examples x = bin(42) print(x) # Prints 0b101010 You can pass a negative number to the function. x = bin(-42) …

Python Built-in Methods – Python ascii() Function

Python ascii() Function Returns a printable version of an object Usage The ascii() function returns a string containing a printable version of an object. It replaces any non-ascii characters with escape characters x, u or U For example, German letter ß will be replaced with xdf. Syntax ascii(object) Parameter Condition Description object Required Any object (such as string, list, tuple, dictionary etc) Basic Example # Return a printable version by …

Python Built-in Methods – Python any() Function

Python any() Function Determines whether any item in an iterable is True Usage The any() function returns True if any item in an iterable is True. Otherwise, it returns False. If the iterable is empty, the function returns False. Syntax any(iterable) Parameter Condition Description iterable Required An iterable of type (list, string, tuple, set, dictionary etc.) Falsy Values In Python, all the following values …

Python Built-in Methods – Python all() Function

Python all() Function Determines whether all items in an iterable are True Usage The all() function returns True if all items in an iterable are True. Otherwise, it returns False. If the iterable is empty, the function returns True. Syntax all(iterable) Parameter Condition Description iterable Required An iterable of type (list, string, tuple, set, dictionary etc.) Falsy Values In Python, all the following values …

Python Built-in Methods – Python abs() Function

Python abs() Function Returns the absolute value of a number Usage The abs() method returns the absolute value of a number. Syntax abs(number) Parameter Condition Description number Required Any number (integer, float or a complex number) Examples # Find absolute value of -10 x = -10 print(abs(x)) # Prints 10 The number may be a floating point number. x = -20.5 print(abs(x)) …

Beginners Guide to Python 3 – Properties in Python

Properties in Python Some object-oriented languages such as Java and C# support private object attributes; which cannot be directly accessed from outside. Programmers often have to write getter and setter methods to access such private attributes. However in Python, all the attributes and methods are public, so it is useless to write getters or setters. …

Beginners Guide to Python 3 – Python Decorators

Python Decorators Sometimes you want to modify an existing function without changing its source code. A common example is adding extra processing (e.g. logging, timing, etc.) to the function. That’s where decorators come in. A decorator is a function that accepts a function as input and returns a new function as output, allowing you to …