DEV Community

Shivani tiwari
Shivani tiwari

Posted on

1 1

Create a class name with variable and Use Constructors to Assign the value creating an object of the class Student.

Hey Everyone ,

Here we solved the python oops problem. About we can read the question . there is some step which we have to follow below-

*What we do first- *

  • We create a class name - That is Student

  • Then we use two variable -One is string that is name and another is integer that is roll_no

  • Then Use the Constructors for assign the value- That is 2 and "John"

Solution

class Student:
       def __init__(self, name, roll_no):
              self.name = name
              self.roll_no = roll_no
Student1= Student("john", 2)
print(Student1.name)
print(Student1.roll_no)

Enter fullscreen mode Exit fullscreen mode

I hope it helps you to solve your query .if you like it do one think follow me for more algo ,python oops updates

Read More Article Here -https://codersvillage.com/

Thank you Everyone
Shivani

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay