Python getattr() Function26 Sept 2024 | 1 min read The python getattr() function returns the value of a named attribute of an object. If it is not found, it returns the default value. SignatureParametersobject: An object whose named attribute value is to be returned. attribute: Name of the attribute of which you want to get the value. default (optional): It is the value to return if the named attribute does not found. ReturnIt returns the value of a named attribute of an object. If it is not found, it returns the default value. Python getattr() Function Example 1The below example shows the working of getattr(). Output: The age is: 22 The age is: 22 Explanation: In the above example, we take a class named as Details that consists of some variables i.e. age, name etc. and returns the value of named attributes of an object in output. Python getattr() Function Example 2The below example shows the working of getattr() when named attribute is not found. Output: The gender is: Male AttributeError: 'Details' object has no attribute 'gender' Next TopicPython Functions |
Function As the name says, python sum() function is used to get the sum of numbers of an iterable, i.e. list. Signature sum(iterable, start) Parameters iterable - iterable can be list, tuples, and dictionaries, but an iterable object must contain numbers. start - The start is added to the sum of...
1 min read
Function function is used to generate hex value of an integer argument. It takes an integer argument and returns an integer converted into a hexadecimal string. In case, we want to get a hexadecimal value of a float then use float.hex() function. The signature of...
1 min read
Function In python, a set is a built-in class, and this function is a constructor of this class. It is used to create a new set using elements passed during the call. It takes iterable as an argument and returns a new set object. The...
1 min read
Function The python frozenset() function returns an immutable frozenset object initialized with elements from the given iterable. Signature frozenset(iterable) Parameters iterable: An iterable object such as list, tuple etc. Return It returns an immutable frozenset object initialized with elements from the given iterable. Function Example 1 The below example shows the working of...
1 min read
Function The python any() function returns True if any item in an iterable is true, otherwise it returns False. Note : If the iterable is empty, then it returns False. Signature any(iterable) Parameters Iterable: It takes an iterable object such as list, dictionary etc. Return It returns true if at least...
2 min read
Function Python is a flexible programming language with a vast library of functions that can make coding a lot more straightforward. Quite possibly of the most remarkable and frequently used function in Python is the eval() function. In this article, we will examine the eval() function...
3 min read
Function function returns an identity of an object. This is an integer which is guaranteed to be unique. This function takes an argument an object and returns a unique integer number which represents identity. Two objects with non-overlapping lifetimes may have the same id() value. Signature id...
1 min read
Function The python abs() function is used to return absolute value of a number. It takes only one argument, a number whose absolute value is to be returned. The argument can be an integer and floating point number. If the argument is a complex number, then,...
1 min read
Function function returns a zip object, which maps a similar index of multiple containers. It takes iterables (can be zero or more), makes it an iterator that aggregates the elements based on iterables passed, and returns an iterator of tuples. Python's zip() function is a built-in...
2 min read
Function The python format() function returns a formatted representation of the given value. Signature format(value, format) Parameters value: It is the value that needs to be formatted. format: It is the specification on how the value should be formatted. Return It returns a formatted representation of the given value. Function Example 1 The...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India