
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to find number of local variables in a function
In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given a function, we need to display the number of local variables in the function.
Now let’s observe the solution in the implementation below −
Example
# checking locals def scope(): a = 25.5 b = 5 str_ = 'Tutorialspoint' # main print("Number of local varibales available:", scope.__code__.co_nlocals)
Output
Number of local varibales available: 3
Example
# checking locals def empty(): pass def scope(): a, b, c = 9, 23.4, True str = 'Tutiorialspoint' # main print("Number of local varibales available:",empty.__code__.co_nlocals) print("Number of local varibales available:",scope.__code__.co_nlocals)
Output
Number of local varibales available: 0 Number of local varibales available: 4
Conclusion
In this article, we have learned about how we can make a Python program to find a number of local variables in a function
- Related Articles
- Global and Local Variables in Python?
- Global vs Local variables in Python
- Python Program for Number of local extrema in an array
- Program to find indices or local peaks in Python
- Program to find local peak element indices from a list of numbers in Python
- Local variables in Java
- Member variables vs Local variables in Java
- System variables vs Local Variables in MySQL?
- User-defined variables vs Local Variables in MySQL?
- Final local variables in C#
- Program to check number of global and local inversions are same or not in Python
- Program to find super digit of a number in Python
- What are class variables, instance variables and local variables in Java?
- What are local variables and global variables in C++?
- Program to find number of nodes in a range in Python

Advertisements