Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
