1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
laiz [17]
3 years ago
14

How does object-oriented programming work in Python?

Computers and Technology
1 answer:
Serggg [28]3 years ago
3 0
So basically you have a class, and within that class you have methods and instance variables; very much like how object oriented programming works in other languages. However, the main difference is that the class constructor in Python is defined right within the class object and is denoted by the method name, "__init__" and requires a parameter of "self". 
Ex:
class Py:
    def __init__(self):
          <em>constructor code...
</em>The __init__ method is what is called first when an object of the class is instantiated. The way you instantiate an object is by the following:
<em />object_name = Py()

If you wanted to make your class more useful, you could add more parameters to your __init__ constructor, so when an object is created you can pass arguments to that object:
class Py:
    def __init__(self, name, age):
         self.name = name
         self.age = age
         print "Your name is %s and you are %d years old" % (name, age)
def main():
     Bob = Py("Bob", 23)
if __name__ == "__main__":
     main()

This code would give you: Your name is Bob and you are 23 years old
You might be interested in
Which statement best describes the problem statement below?
marta [7]

Answer:

B

Explanation:

This problem statement does not clearly define the issues.

7 0
3 years ago
Select all that apply.
Leto [7]
You may do all of the given options.
Thank You!
8 0
3 years ago
Match each code snippet to its appropriate markup language name
Mazyrski [523]

Answer:

Please find the complete solution in the attached file.

Explanation:

8 0
3 years ago
What is a feature of webmail
Fantom [35]

Answer:

Webmail allows the users to access their emails as long as they have access to an Internet connection and a web browser. This also means that the user cannot read an old email or draft a new email offline.

8 0
3 years ago
Which best describes a computer bug?
yanalaym [24]

Answer:

a piece of computer software containing defects that prevent a program from running properly

Explanation:

i got a 100% on the test

6 0
3 years ago
Other questions:
  • And there you go <br> sorry its saying my thing is tooo small
    14·2 answers
  • 25 Points Discuss games you have played that have poor game design puzzles and how you might improve them.
    10·1 answer
  • How do emotions affect purchasing decisions?
    6·1 answer
  • Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout &lt;&lt; fixed &lt;&
    8·1 answer
  • If your database is in archivelog mode, how can you force an archive?
    7·1 answer
  • wants to redesign the user interface. The customer service agents use ________ to enter explicit statement to invoke operations
    11·1 answer
  • Which is the purpose of adding B-Roll footage to a sequence?
    10·1 answer
  • How can a cell phone tower help people​
    11·2 answers
  • Davingould1115...................answer 3​
    11·1 answer
  • true or false You are able to change the formatting of a table after it is inserted into a placeholder.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!