Python program to find number of local variables in a function Last Updated : 10 Jan, 2019 Comments Improve Suggest changes Like Article Like Report Given a Python program, task is to find the number of local variables present in a function. Examples: Input : a = 1 b = 2.1 str = 'GeeksForGeeks' Output : 3 We can use the co_nlocals() function which returns the number of local variables used by the function to get the desired result. Code #1: Python3 # Implementation of above approach # A function containing 3 variables def fun(): a = 1 str = 'GeeksForGeeks' # Driver program print(fun.__code__.co_nlocals) Output: 2 Code #2: Python3 # Python program to find number of # local variables in a function # A function containing no variables def geek(): pass # A function containing 3 variables def fun(): a, b, c = 1, 2.25, 333 str = 'GeeksForGeeks' # Driver program print(geek.__code__.co_nlocals) print(fun.__code__.co_nlocals) Output: 0 4 Comment More infoAdvertise with us Next Article Python program to find number of local variables in a function saurabh_shukla Follow Improve Article Tags : Python Python Programs Python function-programs Practice Tags : python Similar Reads Python Program to Find and Print Address of Variable In this article, we are going to see how to find and print the address of the Python variable. It can be done in these ways:Using id() functionUsing addressof() functionUsing hex() functionMethod 1: Find and Print Address of Variable using id()We can get an address using id() function, id() function 2 min read Python | Program to count number of lists in a list of lists Given a list of lists, write a Python program to count the number of lists contained within the list of lists. Examples: Input : [[1, 2, 3], [4, 5], [6, 7, 8, 9]] Output : 3 Input : [[1], ['Bob'], ['Delhi'], ['x', 'y']] Output : 4 Method #1 : Using len() Python3 # Python3 program to Count number # 5 min read Counting number of unique values in a Python list Counting the number of unique values in a Python list involves determining how many distinct elements are present disregarding duplicates.Using a SetUsing a set to count the number of unique values in a Python list leverages the property of sets where each element is stored only once.Pythonli = [1, 2 min read Python | Find number of lists in a tuple Given a tuple of lists, the task is to find number of lists in a tuple. This is a very basic problem but can be useful while making some utility application. Method #1: Using len Python3 # Python code to find number of list in a tuple # Initial list Input1 = ([1, 2, 3, 4], [5, 6, 7, 8]) Input2 = ([1 4 min read Python program to calculate the number of digits and letters in a string In this article, we will check various methods to calculate the number of digits and letters in a string. Using a for loop to remove empty strings from a list involves iterating through the list, checking if each string is not empty, and adding it to a new list.Pythons = "Hello123!" # Initialize cou 3 min read Accessing Python Function Variable Outside the Function In Python, function variables have local scope and cannot be accessed directly from outside. However, their values can still be retrieved indirectly. For example, if a function defines var = 42, it remains inaccessible externally unless retrieved indirectly.Returning the VariableThe most efficient w 4 min read Find the Length of a String Without Using len Function in Python In this article, we will explore different methods to find the length of a string without using the len() function in Python. We will look at several techniques like loops, recursion, and generator expressions. These approaches help us manually calculate the length of a string.Using sum()sum() with 2 min read Frequency of Numbers in String - Python We are given a string and we have to determine how many numeric characters (digits) are present in the given string. For example: "Hello123World456" has 6 numeric characters (1, 2, 3, 4, 5, 6).Using re.findall() re.findall() function from the re module is a powerful tool that can be used to match sp 3 min read Python program to find sum of elements in list Finding the sum of elements in a list means adding all the values together to get a single total. For example, given a list like [10, 20, 30, 40, 50], you might want to calculate the total sum, which is 150. Let's explore these different methods to do this efficiently.Using sum()sum() function is th 3 min read Count Occurance of Substring in a List of Strings - Python To count the occurrences of a particular substring in a list of strings in Python, we can use several methods. In this article, we are going to explore different methods to count the existence of a particular substring in a given list.Using sum() and Generator ExpressionThis method uses a generator 2 min read Like