How to assign values to attributes [closed]
I am a newbie in python and am trying to write and execute a python code that returns student name, age and grade but on executions gives me an error message that:"Students() takes no arguments."
Here is my code:
class Students:
def _init_ (self,name,age,grade):
self.name=name
self.age=age
self.grade=grade
student1=Students('Bob',12,'7th')
Student1.name
Student1.age
Student.grade
I want the code to return to me 'Bob' as the student's name,12 as age and 7th as the student grade.
python class object
closed as off-topic by Daniel Roseman, tripleee, eyllanesc, jww, Makyen Jan 2 at 6:01
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Daniel Roseman, tripleee, eyllanesc, jww, Makyen
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I am a newbie in python and am trying to write and execute a python code that returns student name, age and grade but on executions gives me an error message that:"Students() takes no arguments."
Here is my code:
class Students:
def _init_ (self,name,age,grade):
self.name=name
self.age=age
self.grade=grade
student1=Students('Bob',12,'7th')
Student1.name
Student1.age
Student.grade
I want the code to return to me 'Bob' as the student's name,12 as age and 7th as the student grade.
python class object
closed as off-topic by Daniel Roseman, tripleee, eyllanesc, jww, Makyen Jan 2 at 6:01
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Daniel Roseman, tripleee, eyllanesc, jww, Makyen
If this question can be reworded to fit the rules in the help center, please edit the question.
2
The initialization of Python classes is handled by a method named__init__()
. A method named_init_()
(note different number of underscores) has no particular meaning.
– jasonharper
Jan 2 at 2:55
add a comment |
I am a newbie in python and am trying to write and execute a python code that returns student name, age and grade but on executions gives me an error message that:"Students() takes no arguments."
Here is my code:
class Students:
def _init_ (self,name,age,grade):
self.name=name
self.age=age
self.grade=grade
student1=Students('Bob',12,'7th')
Student1.name
Student1.age
Student.grade
I want the code to return to me 'Bob' as the student's name,12 as age and 7th as the student grade.
python class object
I am a newbie in python and am trying to write and execute a python code that returns student name, age and grade but on executions gives me an error message that:"Students() takes no arguments."
Here is my code:
class Students:
def _init_ (self,name,age,grade):
self.name=name
self.age=age
self.grade=grade
student1=Students('Bob',12,'7th')
Student1.name
Student1.age
Student.grade
I want the code to return to me 'Bob' as the student's name,12 as age and 7th as the student grade.
python class object
python class object
edited Jan 2 at 4:34
Strom
2,368524
2,368524
asked Jan 2 at 2:41
Wycliffe MuchumiWycliffe Muchumi
11
11
closed as off-topic by Daniel Roseman, tripleee, eyllanesc, jww, Makyen Jan 2 at 6:01
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Daniel Roseman, tripleee, eyllanesc, jww, Makyen
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by Daniel Roseman, tripleee, eyllanesc, jww, Makyen Jan 2 at 6:01
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Daniel Roseman, tripleee, eyllanesc, jww, Makyen
If this question can be reworded to fit the rules in the help center, please edit the question.
2
The initialization of Python classes is handled by a method named__init__()
. A method named_init_()
(note different number of underscores) has no particular meaning.
– jasonharper
Jan 2 at 2:55
add a comment |
2
The initialization of Python classes is handled by a method named__init__()
. A method named_init_()
(note different number of underscores) has no particular meaning.
– jasonharper
Jan 2 at 2:55
2
2
The initialization of Python classes is handled by a method named
__init__()
. A method named _init_()
(note different number of underscores) has no particular meaning.– jasonharper
Jan 2 at 2:55
The initialization of Python classes is handled by a method named
__init__()
. A method named _init_()
(note different number of underscores) has no particular meaning.– jasonharper
Jan 2 at 2:55
add a comment |
1 Answer
1
active
oldest
votes
You have not included a constructor for Students, your code creates a method named _init()_
not the constructor __init()__
.
Also, Python is case sensitive, make sure all of your identifiers match case and spelling.
class Students:
def __init__ (self,name,age,grade):
self.name=name
self.age=age
self.grade=grade
student1=Students('Bob',12,'7th')
student1.name
student1.age
student1.grade
It worked,Thank you guys.
– Wycliffe Muchumi
Jan 11 at 9:40
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have not included a constructor for Students, your code creates a method named _init()_
not the constructor __init()__
.
Also, Python is case sensitive, make sure all of your identifiers match case and spelling.
class Students:
def __init__ (self,name,age,grade):
self.name=name
self.age=age
self.grade=grade
student1=Students('Bob',12,'7th')
student1.name
student1.age
student1.grade
It worked,Thank you guys.
– Wycliffe Muchumi
Jan 11 at 9:40
add a comment |
You have not included a constructor for Students, your code creates a method named _init()_
not the constructor __init()__
.
Also, Python is case sensitive, make sure all of your identifiers match case and spelling.
class Students:
def __init__ (self,name,age,grade):
self.name=name
self.age=age
self.grade=grade
student1=Students('Bob',12,'7th')
student1.name
student1.age
student1.grade
It worked,Thank you guys.
– Wycliffe Muchumi
Jan 11 at 9:40
add a comment |
You have not included a constructor for Students, your code creates a method named _init()_
not the constructor __init()__
.
Also, Python is case sensitive, make sure all of your identifiers match case and spelling.
class Students:
def __init__ (self,name,age,grade):
self.name=name
self.age=age
self.grade=grade
student1=Students('Bob',12,'7th')
student1.name
student1.age
student1.grade
You have not included a constructor for Students, your code creates a method named _init()_
not the constructor __init()__
.
Also, Python is case sensitive, make sure all of your identifiers match case and spelling.
class Students:
def __init__ (self,name,age,grade):
self.name=name
self.age=age
self.grade=grade
student1=Students('Bob',12,'7th')
student1.name
student1.age
student1.grade
answered Jan 2 at 3:11
StromStrom
2,368524
2,368524
It worked,Thank you guys.
– Wycliffe Muchumi
Jan 11 at 9:40
add a comment |
It worked,Thank you guys.
– Wycliffe Muchumi
Jan 11 at 9:40
It worked,Thank you guys.
– Wycliffe Muchumi
Jan 11 at 9:40
It worked,Thank you guys.
– Wycliffe Muchumi
Jan 11 at 9:40
add a comment |
2
The initialization of Python classes is handled by a method named
__init__()
. A method named_init_()
(note different number of underscores) has no particular meaning.– jasonharper
Jan 2 at 2:55