Table of Contents
Python program to access global variable in class
Simple python program to access global variable in class.
Access global variable in class in python
class Employee:
emp_count=0
def __init__(self,name,age):
self.name=name
self.age=age
Employee.emp_count+=1
def displayCount(self):
print(“Total employee “,Employee.emp_count)
def displstEmployee(self):
print(“Name : “,self.name,” | Age : “,self.age)
e1=Employee(“Rajiv”,24)
e2=Employee(“Anish”,23)
e1.displstEmployee()
e2.displstEmployee()
print(“Total employee “,Employee.emp_count)
Output

We are aiming to explain all concepts of python in easiest terms as possible.

ITVoyagers
Author
PRACTICALS/PRACTICE PROGRAM IN PYTHON
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on File Handling |
Easy quiz on file handling in python part 1 |
Easy quiz on file handling in python part 2 |
Quizzes on Exception Handling |
Easy quiz on Exception Handling in python part 1 |
Easy Quiz on Exception Handling in python part 2 |
Quizzes on Regular Expressions |
Easy Quiz on Regular Expression in python part 1 |
Quizzes on Python concepts coming soon… |
Python basic quiz |
New and easy python quiz basic part 1 |
New and easy python quiz (basic) part 2 |
New and easy python quiz (basic) part 3 |
Python practice quiz set |
Best Practice Quiz Set on Python Programming Part 1 |
Best Practice Quiz Set on Python Programming Part 2 |
Best Practice Quiz Set on Python Programming Part 3 |
Best Practice Quiz Set on Python Programming Part 4 |
Best Practice Quiz Set on Python Programming Part 5 |