Here is a python class to print student details. The student details are first name, last name, student id.
Python supports object-oriented programming. So you can write classes in python fearlessly. One thing to remember is ‘SELF’ argument is a must in the init method.
Here’s how to write and execute Python script
In two steps you will learn:
- Python program
- Execution of the program
1. Sample Python program
It tells how to write class to display student details.

Here I’ve created two methods – init and str. In addition to that, I have supplied self argument. At the line, number4 defined init methods, and at line number8 defined str.
Both are internal methods. In the init method, I did initialization. In the str method, I used initialized variables to concatenate the string.
Learnings
- Let us say, by mistake you typed init method/str method name incorrrectly, then you’ll get Type error
- The supplied self argument in the str method helps to get initilized variables
- By default in all the methods you need to supply self argument
“The ability to observe without evaluating is the highest form of intelligence.”
― J. Krishnamurti, Author of Freedom from the known
2. Execution of the program
You’ll see the output of the program.

So in the output, you can see concatenated student details (first-name, last-name and student id). Useful for your project and interviews.
Related posts
You must be logged in to post a comment.