Python exec() Function26 Sept 2024 | 1 min read The python exec() function is used for the dynamic execution of Python program which can either be a string or object code and it accepts large blocks of code, unlike the eval() function which only accepts a single expression. Signatureexec(object, globals, locals) Parametersobject - It should be either string or code object. globals (optional) - It is used to specify global functions. locals (optional) - It is used to specify local functions. Let's see some examples of exec() function which are given below: Python exec() Function Example 1This example shows working of exec() function. Output: True 9 Python exec() Function Example 2This example shows exec() dynamic code execution Output: Enter Code Snippet to execute: print(sqrt(16)) 4.0 Enter Code Snippet to execute: print(min(2,1)) 1 Done Next TopicPython Built in Functions |
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 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 Python has() function is used to get the hash value of an object. Python calculates the hash value by using the hash algorithm. The hash values are integers an used to compare dictionary keys during a dictionary lookup. We can hash only these types: Hashable types:...
2 min read
Function The python bytes() function in Python is used for returning a bytes object. It is an immutable version of bytearray() function. It can create empty bytes object of the specified size. Signature bytes(source) bytes(encoding) bytes(error) Parameters source is used to initialize the bytes object. It is an optional parameter. encoding is optional unless...
1 min read
Function The python list() creates a list in python. Signature list(iterable) Parameters iterable (optional) - An object that can be a sequence( string, tuple etc.) or collection( set, dictionary etc.) or iterator object. Return It returns a list. Function Example 1 The below example create a list from sequence: string, tuple and list. #...
1 min read
Function function returns an enumerated object. It takes two parameters first is a sequence of elements and the second is the start index of the sequence. We can get sequence elements either through a loop or () method. The () method of the iterator returned...
3 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 function returns the list of names in the current local scope. If the object on which method is called has a method named __dir__(), this method will be called and must return the list of attributes. It takes a single object type argument....
2 min read
Function The python memoryview() function returns a memoryview object of the given argument. Before we come to the memoryview, we have to understand about Python's Buffer Protocol. Buffer Protocol provides a way to access internal data of an object. This internal data is a memory array or a...
2 min read
Function A python callable() function in Python is something that can be called. This built-in function checks and returns True if the object passed appears to be callable, otherwise False. Signature callable(object) Parameters object - The object that you want to test and check, it is callable or...
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