Using a Class with Input in Python Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 9 Likes Like Report In this article, we will see how to take input using class in Python. Using a Class with Input in Python It is to be noted that while using class in Python, the __init__() method is mandatory to be called for declaring the class data members, without which we cannot declare the instance variable (data members) for the object of the class. A variable declared outside the __init__() methods is termed as the class variable such as stuCount variable in the below program. It is to be noted that the class variable is accessed by className.classVariableName, e.g., Student.StuCount in the above program. However, the instance variables or data members are accessed as self.instanceVariableName. Python # Illustration of creating a class # in Python with input from the user class Student: 'A student class' stuCount = 0 # initialization or constructor method of def __init__(self): # class Student self.name = input('enter student name:') self.rollno = input('enter student rollno:') Student.stuCount += 1 # displayStudent method of class Student def displayStudent(self): print("Name:", self.name, "Rollno:", self.rollno) stu1 = Student() stu2 = Student() stu3 = Student() stu1.displayStudent() stu2.displayStudent() stu3.displayStudent() print('total no. of students:', Student.stuCount) Output: In this program, we see that the input() function is called in the definition of __init__() method for inputting the values of data variables name and rollno. Subsequently, the value of stuCount is incremented by 1 in order to keep track of the total number of objects created for the class Student. In this program, three objects stu1, stu2, and stu3 are created thereby calling the constructor function __init__() three times. The values are assigned to name and rollno after input from the user. Then, the result is displayed by calling the displayStudent() function of class Student. The output of this program can be preferred for more lucidity. Create Quiz Comment A arpitkhushwaha Follow 9 Improve A arpitkhushwaha Follow 9 Improve Article Tags : Python python-basics python-oop-concepts Python-OOP Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like