简体   繁体   中英

Hi can someone please help me. i don't know what the problem is and I'm new to coding. im using python and im trying to create a class Student

class Student:
    def __init__(self, studentName, roll_no):
        self.studentName = studentName
        self.roll_no = roll_no

    def displayStudentInfo(self):
        std = Student("John", 2)
        print("name is: ", std.studentName + "roll number is;" , std.roll_no)

When I run it it comes back as =RESTART: C:\Users...

Same when I try to debug it...I don't know if the code is the problem how I saved it or the environment I'm running it on??

The **Restart <filename>...** line is IDLE's way of telling you that it has restarted the interactive session so that the workspace is as empty as when you normally start python. In other words, everything above the line has effectively been erased. It also tells you what file, if any, it is running. This is needed if you have multiple editor windows open.

When I edited your question to reformat the code, I fixed some minor errors. Below is something like what I think you meant to do, which fixes the major errors.

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

    def display(self):
        print(f"name: {self.name}; roll number: {self.roll_no}")

std = Student("John", 2)
std.display()

After you define a class, you need to do something with it in order to see any output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM