Using a Class with Input in Python Last Updated : 20 Feb, 2022 Comments Improve Suggest changes Like Article 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. Comment More infoAdvertise with us Next Article Using a Class with Input in Python A arpitkhushwaha Follow Improve Article Tags : Python python-basics python-oop-concepts Python-OOP Practice Tags : python Similar Reads Taking input in Python Developers often have a need to interact with users, either to get data or to provide some sort of result. Most programs today use a dialog box as a way of asking the user to provide some type of input. While Python provides us with two inbuilt functions to read the input from the keyboard. input () 3 min read Inner Class in Python Python is an Object-Oriented Programming Language, everything in Python is related to objects, methods, and properties. A class is a user-defined blueprint or a prototype, which we can use to create the objects of a class. The class is defined by using the class keyword.Example of classPython# creat 5 min read Using User Input to Call Functions - Python input() function allows dynamic interaction with the program. This input can then be used to call specific functions based on the user's choice .Letâs take a simple example to call function based on user's input .Example:Pythondef add(x, y): return x + y # Add def sub(x, y): return x - y # Subtract 2 min read Taking input from console in Python What is Console in Python? Console (also called Shell) is basically a command line interpreter that takes input from the user i.e one command at a time and interprets it. If it is error free then it runs the command and gives required output otherwise shows the error message. A Python Console looks 2 min read Get a list as input from user in Python We often encounter a situation when we need to take a number/string as input from the user. In this article, we will see how to take a list as input from the user using Python.Get list as input Using split() MethodThe input() function can be combined with split() to accept multiple elements in a sin 3 min read Like