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 …
Day: May 13, 2021
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 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 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 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 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)) …
Python File Handling Python provides a wide range of built-in functions for file handling. It makes it really easy to create, update, read, and delete files. Open a File When you want to work with a file, the first thing to do is to open it. You can open a file using open() built-in function specifying its …
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. …
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 …
Python Classes and Objects Classes and objects are the two main aspects of object-oriented programming. A class is the blueprint from which individual objects are created. In the real world, for example, there may be thousands of cars in existence, all of the same make and model. Each car was built from the same set …