Python OOP Exercise -


I am trying to use classes in Python, and have written this exam program. This is somewhat of what I found in another question which I found here on stack overflow.

The code looks as follows:

  class student (object): name = "" age = 0 major = "" # class "constructor" - this is actually an initial Def __init __ (self, name, age, major) is: self.name = name self.age = age self.major = major def list_values ​​(): print "name:", self.name print "age:", self . Print "Major:", self. Major def (name, age, major): student = student (name, age, major) return student print "a list of students." Steve = Melchistant ("Steven Schultz", 23, "English") Johnny = Macstastent ("Jonathan Rosenberg", 24, "Biology") Panny = Macstastant ("Penelope Marmolytakis", 21, "Physics") Steve.List_Value () Johnny.list_values ​​() Penny.list_values ​​()   

When I run it, get error "TypeError: list_values ​​() does not take any arguments (1 given) ) ". In my opinion, I have not given any argument, but I remove the bracket, giving the code

  Steve List_names Johnny.list_values ​​Penny.list_values ​​  

this

My question:

  1. What is the deal with brackets?
  2. What's the deal with print statement?

    list_type method is required for your student example To be bound:

    You should change:

      def list_values ​​()   

    to:

      def list_values ​​(self)   

    Why, to see:

    • < Besides this, this blog post by Guido also includes:



Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -