Skip to content

Latest commit

History

History
46 lines (36 loc) 路 994 Bytes

File metadata and controls

46 lines (36 loc) 路 994 Bytes

Student Class Example

This is my first repository on GitHub. 馃帀
It includes a simple example of a Python class named Student that stores and displays student information.

馃 What This Code Does

  • Defines a Student class with attributes:
    • name
    • age
    • grade
  • Uses a display_info() method to neatly return the student's information.
  • Creates an instance of Student and prints the info.

馃Ь Code Example

class Student:
    def __init__(self, name, age, grade):
        self.name = name
        self.age = age
        self.grade = grade

    def display_info(self):
        return f"Name: {self.name} \nAge: {self.age}\nGrade: {self.grade}"

s1 = Student("hassan", 12, "d")
print(s1.display_info())

馃枿 Output

Name: hassan 
Age: 12
Grade: d

馃搧 How to Run

  1. Make sure Python is installed on your system.

2.Copy the code into a file named student.py.

  1. Run the file in your terminal or command prompt:1
python main.py