Function |
Example |
Description |
abs() |
Code
![](images3/3505a.png)
Output: ![](images3/3505b.png)
|
|
aiter() |
Code
![](images3/3505c.png)
Output: ![](images3/3505d.png)
|
The aiter() function is used for asynchronous iteration. async_generator() is an asynchronous generator that yields values from 0 to 4 with a 1-second delay between each yield (each number). |
all() |
Code
![](images3/3505e.png)
Output: ![](images3/3505f.png)
|
The all() function returns True if all elements in the given iterable are True. If the iterable is empty, it also returns True. Otherwise, it returns False.
If the iterable is empty, all() returns True because there are no elements to evaluate.
If the iterable contains at least one element that evaluates to False, all() returns False immediately without evaluating the rest of the elements.
If all elements in the iterable are True, all() returns True. |
anext() |
|
__anext__() is a special method used in asynchronous iterators to define the behavior of retrieving the next item asynchronously. When you use async for item in async_iterator, Python internally calls __anext__() on the async iterator to fetch the next item asynchronously. |
any() |
Code
![](images3/3505g.png)
Output: ![](images3/3505h.png)
|
The any() function in Python is a built-in function that returns True if at least one element of the iterable passed to it evaluates to True. If all elements in the iterable evaluate to False, any() returns False. If the iterable is empty, any() returns False as well, since there are no elements to evaluate.
It takes an iterable (such as a list, tuple, set, or any other iterable object) as its argument.
It iterates over each element in the iterable.
If it finds an element that evaluates to True, it immediately returns True, without iterating over the remaining elements.
If it doesn't find any element that evaluates to True, it returns False. |
ascii() |
|
The ascii() function in Python returns a string containing a printable representation of an object. It's similar to the repr() function but specifically aimed at producing ASCII characters.
For strings: It escapes non-ASCII characters in the string using \x, \u, or \U escapes. This ensures that the resulting string contains only ASCII characters and is suitable for representing non-ASCII characters in a way that can be handled by ASCII-based systems.
For other objects: It calls the object's __repr__() method to obtain its representation and then applies the same escaping rules for non-ASCII characters as it does for strings. |
bin() |
|
The bin() function in Python is used to convert an integer into its binary representation. |
bool() |
Code
![](images3/3505i.png)
Output: ![](images3/3505j.png)
|
The bool() function is used to convert a value to a Boolean (True or False) representation. It evaluates the truthiness of a given value.
If the argument is omitted or None, it returns False.
If the argument is a boolean value (True or False), it returns the same value.
For numeric types (integers, floats), it returns False if the argument is zero, and True otherwise.
For sequences (lists, tuples, strings, etc.), it returns False if the sequence is empty, and True otherwise.
For other types, it usually returns True. |
breakpoint() |
|
breakpoint() is a Python built-in function to simplify the process of setting breakpoints for debugging. It essentially acts as a shortcut for inserting a breakpoint into your code. When executed, it pauses the execution of the program and drops you into the Python debugger (PDB) at the point where the breakpoint() function was called. |
bytearray() |
|
The bytearray() function in Python is used to create a mutable sequence of bytes. |
bytes() |
|
The bytes() function in Python is used to convert a sequence of integers (between 0 and 255) into a bytes object. |
callable() |
|
callable() function can be used to check if different objects such as functions, classes, and instances are callable or not. It defines various objects like functions, classes, and instances, and then iterates through a list to check if each one is callable or not. |
chr() |
|
The chr() function in Python takes an integer Unicode code point and returns a string representing a character at that code point. |
classmethod() |
|
classmethod() is a built-in function in Python used to define a method that operates on the class itself, rather than on instances of the class. |
compile() |
|
The compile() function in Python is used to compile source code into a code or AST object that can be executed later. |
complex() |
|
The complex() function in Python is used to create a complex number object. |
delattr() |
|
The delattr() function in Python is used to delete an attribute from an object if the attribute exists. |
dict() |
Code:
Output:
![Automatically Review, Scroll, Click Webpage and Its Link](images/4276b.png) |
The dict() function in Python is used to create a new dictionary object. It can take various forms of input to initialize the dictionary, such as another dictionary, a sequence of key-value pairs, keyword arguments, etc. |
dir() |
|
The dir() function in Python is used to get a list of attributes and methods of any object, including built-in objects, modules, classes, or instances. Introduction. |
divmod() |
Code
![](images3/3505ha.png)
Output: ![](images3/3505hb.png)
|
This script prompts the user to enter two numbers, then uses the divmod() function to compute the quotient and remainder when the first number is divided by the second number. Finally, it prints the quotient and remainder. |
enumerate() |
Code
![](images3/3505hc.png)
Output: ![](images3/3505hd.png)
|
This script creates a list of fruits and then iterates over each element in the list using the enumerate() function. enumerate() returns both the index and the value of each element in the list, making it convenient for iterating over lists while also having access to their indices. Introduction. |
eval() |
Code
![](images3/3505hg.png)
Output: ![](images3/3505hh.png)
|
The eval() function in Python is used to evaluate a string as a Python expression, essentially allowing dynamic execution of Python code |
exec() |
Code
![](images3/3505hi.png)
Output: ![](images3/3505hj.png)
|
exec() is a Python built-in function that is used to execute a dynamically created Python code (script). This script demonstrates how exec() can be used to execute dynamically created Python code. In this example, the Python code is stored in the variable code as a string, and exec() is used to execute it. You can also provide a specific namespace (dictionary) where the executed code will have its variables stored. |
filter() |
Code
![](images3/3505hk.png)
Output: ![](images3/3505hl.png)
|
The filter() function in Python is used to filter elements of an iterable (like lists, tuples, etc.) based on a given function.
In this script: We define a function is_even() which returns True if a number is even, otherwise False. We create a list of numbers called numbers. We use the filter() function to filter even numbers from the numbers list based on the is_even() function. We convert the filtered result into a list using list(). Finally, we print the filtered even numbers. |
float() |
|
The float() function in Python is used to convert a number or a string representing a number to a floating-point number (a number with a decimal point). |
format() |
Code
![](images3/3505ia.png)
Output: ![](images3/3505ib.png)
|
The format() function is ued for string formatting, including basic string formatting, positional arguments, named arguments, mixed arguments, formatting floating-point numbers, and using dictionaries and lists with format(). |
frozenset() |
|
The frozenset() function in Python returns an immutable frozenset object initialized with elements from the given iterable. |
getattr() |
|
getattr() is a Python built-in function that returns the value of a named attribute of an object. If the attribute doesn't exist, it returns a default value, or raises an AttributeError if no default is provided. |
globals() |
|
The globals() function in Python returns a dictionary representing the global symbol table. This dictionary includes all global variables and their corresponding values within the current scope. |
hasattr() |
|
hasattr() is a built-in Python function used to check if an object has a particular attribute or not. |
hash() |
|
The hash() function in Python is used to generate a hash value (a fixed-size integer) for a given object. The hash value is computed based on the object's contents and is typically used for fast data retrieval in data structures like dictionaries and sets. |
help() |
|
The help() function in Python is used to display documentation about modules, functions, classes, and methods. |
hex() |
|
The hex() function in Python converts an integer number to a lowercase hexadecimal string prefixed with "0x". |
id() |
|
The id() function in Python returns the identity of an object. This identity is unique and constant for this object during its lifetime. |
input() |
|
The input() function in Python is used to take input from the user during runtime. When input() is called, the program will pause execution and wait for the user to enter some text (followed by pressing the Enter key). Whatever the user enters is treated as a string and is returned as the result of the input() function. |
int() |
|
The int() function in Python is used to convert a given value into an integer. If the value is a string, it can be converted to an integer if it represents a valid integer literal. If the value is a floating-point number, it will be truncated towards zero. |
isinstance() |
Code
![](images3/3503aa.png)
Output: ![](images3/3503ab.png)
|
The isinstance() function in Python is used to check whether an object is an instance of a specified class or its subclasses.
The example is to check instances using isinstance(): 1) We define three classes: Vehicle, Car, and Motorcycle. Car and Motorcycle are subclasses of Vehicle. However, we didn't define any attributes or methods for simplicity, so they are just empty classes. 2) We then instantiate objects of these classes: vehicle, car, and motorcycle. 3) The isinstance() function is used to check if an object is an instance of a specified class or its subclasses. We use it to check the type of each object we instantiated.
Introduction. |
issubclass() |
|
The issubclass() function in Python is used to check whether a class is a subclass of another class. |
iter() |
Code
![](images3/3502a.png)
Output: ![](images3/3502bb.png)
|
The iter() function in Python returns an iterator object for the given iterable (such as a list, tuple, dictionary, etc.). |
len() |
|
The len() function in Python is used to return the number of items (length) in an object. It can work with various types of objects, including sequences (such as lists, tuples, strings), collections (such as dictionaries, sets), and other iterable objects. |
list() |
Code
![](images3/3505ja.png)
Output: ![](images3/3505jb.png)
|
The list() function in Python is used to create a new list object. It can convert various iterable objects, such as tuples, strings, dictionaries, sets, or even other lists, into a new list. |
locals() |
Code
![](images3/3505jc.png)
Output: ![](images3/3505jd.png)
|
When we run this script, it defines a function my_function() which assigns values to variables x and y. Inside the function, it calls locals() to get a dictionary containing all local variables within the function. Finally, it prints out the local variables and their types.
Introduction. |
map() |
Code
![](images3/3505jg.png)
Output: ![](images3/3505jh.png)
|
The map() function in Python is used to apply a given function to all the elements of an iterable (like a list) and returns an iterator of the results. |
max() |
Code
![](images3/3505ji.png)
Output: ![](images3/3505jj.png)
|
The max() function in Python returns the largest item in an iterable or the largest of two or more arguments. |
memoryview() |
|
memoryview() in Python provides a memory view object that exposes the buffer interface of an object. This allows us to access the memory of an object's data directly, without needing to make a copy. |
min() |
Code
![](images3/3505jk.png)
Output: ![](images3/3505jl.png)
|
The min() function in Python is used to find the minimum value among the arguments passed to it or the minimum value from an iterable. |
next() |
Code
Output:
|
The next() function in Python is used to retrieve the next item from an iterator. It takes an iterator object as an argument and returns the next item in the sequence. When there are no more items to retrieve, it raises a StopIteration exception.
Introduction. |
object() |
|
The object() function in Python returns a new featureless object. It's mainly used as a base for new-style classes. |
oct() |
|
The oct() function in Python is used to convert an integer number to its octal representation as a string. |
open() |
The open() function in Python is used to open files. It returns a file object that provides methods and attributes for working with the file. The function accepts two main parameters: the file name (or path) and the mode in which the file should be opened. Introduction. |
ord() |
|
The ord() function in Python returns the Unicode code point for a given character. |
pow() |
Code
![](images3/3505js.png)
Output: ![](images3/3505jt.png)
|
The pow() function in Python is used to calculate the power of a number. It takes two arguments: the base number and the exponent. The function returns the result of raising the base to the power of the exponent. |
print() |
|
In Python, the print() function is used to display the specified message or value(s) on the screen or console. It takes one or more arguments which can be of various types, such as strings, numbers, variables, or even other data structures like lists or dictionaries. |
property() |
|
The property() function in Python is a built-in function that creates and returns a property object. Properties are special kind of attributes which allow defining getter, setter, and deleter methods that are automatically called when the property is accessed, assigned to, or deleted. This enables you to encapsulate the access to attributes and perform additional actions (such as validation) when getting, setting, or deleting them. |
range() |
Code
![](images3/3505k.png)
Output: ![](images3/3505l.png)
|
In range() function, when specifying a range with two arguments, the first argument is the starting point, and the second argument is the ending point (exclusive). In the example, the range(10, 1) would create an empty sequence because it starts at 10 and ends before reaching 1, but since it's moving in the default increment of 1, it can't reach 1 from 10.
The range function doesn't inherently support backward iteration. To iterate in reverse, you can use negative step size with range().
Other examples of using range() are: code1: pattern, code2: numbers, code3: numbers, code4: number pattern. image |
repr() |
|
The repr() function in Python returns a string representation of an object. It's typically used to get a string representation of an object that is as close as possible to valid Python expression that would recreate the object when passed to eval(), helping with debugging and logging. |
reversed() |
Code
![](images3/3505ju.png)
Output: ![](images3/3505jv.png)
|
The reversed() function in Python returns an iterator that yields items from a sequence in reverse order.
Introduction. |
round() |
|
In Python, the round() function is used to round a floating-point number to a specified number of decimal places or to the nearest integer if no decimal places are specified. |
set() |
|
In Python, the set() function is used to create a set data structure. A set is an unordered collection of unique elements. When we pass an iterable (like a list, tuple, string, etc.) to the set() function, it returns a new set containing the unique elements from that iterable, removing any duplicates. |
setattr() |
|
In Python, the setattr() function is used to set the value of an attribute of an object. It takes three arguments: 1) The object whose attribute you want to set. 2) The name of the attribute you want to set. 3) The value we want to assign to the attribute. |
slice() |
Code
![](images3/3505jw.png)
Output: ![](images3/3505jx.png)
|
In Python, the slice() function creates a slice object that represents a range of indices that can be used to slice sequences such as lists, tuples, and strings.
Introduction. |
sorted() |
Code
![](images3/3505jy.png)
Output: ![](images3/3505jz.png)
|
The sorted() function in Python is used to sort any iterable object like lists, tuples, or strings, and returns a new sorted list.
Introduction. |
staticmethod() |
|
The staticmethod() function in Python is a built-in function that is used as a decorator to define a static method in a class. Static methods are methods that belong to the class rather than any specific instance of the class. They can be called on the class itself, without requiring an instance of the class to be created. |
str() |
|
In Python, the str() function is used to convert a value into a string representation. It can convert various types of data, such as integers, floats, lists, tuples, dictionaries, etc., into a string. |
sum() |
|
In Python, the sum() function is used to calculate the sum of elements within an iterable, such as a list, tuple, or set. It takes an iterable (a collection of elements) as its argument and returns the sum of all the elements within that iterable. |
super() |
|
In Python, the super() function is used to call methods and access attributes from the parent class within a subclass. It returns a proxy object that delegates method calls to a parent or sibling class, allowing you to invoke methods defined in the superclass. |
tuple() |
|
In Python, the tuple() function is used to create a tuple object. A tuple is an immutable collection of ordered elements, which can be of any data type. |
type() |
|
In Python, the type() function is used to get the type of an object. It returns the type of the object passed as an argument. |
vars() |
|
In Python, the vars() function returns the __dict__ attribute of an object if it exists, which is a dictionary containing the object's namespace (attributes and their values). If the object does not have a __dict__ attribute, vars() behaves as locals() and returns the local namespace when called without arguments inside a function, or the global namespace when called outside of a function. |
zip() |
Code
![](images3/3505ka.png)
Output: ![](images3/3505kb.png)
|
In Python, the zip() function is used to combine multiple iterables (such as lists, tuples, etc.) element-wise into a single iterable object. It returns an iterator of tuples where the i-th tuple contains the i-th element from each of the input iterables. If the input iterables are of different lengths, the returned iterator will only have as many elements as the shortest iterable.
Introduction. |
__import__() |
|
In Python, the __import__() function is a low-level mechanism to dynamically import modules. It allows you to import a module programmatically at runtime.
The __import__() function is not typically used in everyday Python programming because using the import statement directly is simpler and more readable. |