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 Like