Given a Python program, task is to find the number of local variables present in a function.
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.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Global and Local Variables in Python
- Python Program to Swap Two Variables
- Create Local Binary Pattern of an image using OpenCV-Python
- Unused local variable in Python
- Setup Python in a Local Computer
- Mahotas - Bernsen local thresholding
- Mahotas - Local Minima in Image
- Mahotas - Local Maxima in Image
- Class or Static Variables in Python
- Python | Set 2 (Variables, Expressions, Conditions and Functions)
- Python | Extract key-value of dictionary in variables
- Private Variables in Python
- Python | Difference between Pandas.copy() and copying through variables
- How to assign values to variables in Python and other languages
- Python | Assign multiple variables with list values
- Inserting variables to database table using Python
- How are variables stored in Python - Stack or Heap?
- Python | Unpack whole list into variables
- Python Scope of Variables
- Tracing Tkinter variables in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.