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
OSHA standards appear in the ___________ and are then broken down into ____________.
Alisiya [41]
OSHA standards appear in the Code of Federal Regulations (CFR) <span>and was then broken down into two parts. It contains standards to ensure a </span>
4 0
2 years ago
Which programming element is used by a game program to track and display score information
laiz [17]
I think the answer is variables.
4 0
3 years ago
Read 2 more answers
In Online Data Extraction data is extracteddirectly from the ------ system itself.o Hosto Destinationo Sourceo Terminal
barxatty [35]

Answer:

system itself.

Explanation:

In Online Data Extraction data is extracted directly from the system itself.

4 0
3 years ago
Write a program that calculates and displays the amount ofmoney available in a bank account that initially has $8000 deposited i
Leviafan [203]

Answer:

Written in Python

import math

principal = 8000

rate = 0.025

for i in range(1, 11):

    amount = principal + principal * rate

    principal = amount

    print("Year "+str(i)+": "+str(round(amount,2)))

Explanation:

This line imports math library

import math

This line initializes principal amount to 8000

principal = 8000

This line initializes rate to 0.025

rate = 0.025

The following is an iteration from year 1 to 10

for i in range(1, 11):

    This calculates the amount at the end of the year

    amount = principal + principal * rate

    This calculates the amount at the beginning of the next year

    principal = amount

    This prints the calculated amount

    print("Year "+str(i)+": "+str(round(amount,2)))

6 0
3 years ago
010101010101011101011
sattari [20]
Whatwhatwhatwhat???????????
6 0
3 years ago
Other questions:
  • What are three new things in Microsoft Word 2016?
    5·1 answer
  • 7. What is the school campus’s setting<br> the school is sanford
    6·2 answers
  • Jawana has been working on a paper for her Anatomy class for weeks. One day her little brother was on her computer and accidenta
    14·1 answer
  • In the context of Information Technology Infrastructure Library, _____ delivers information technology IT services on an ongoing
    14·1 answer
  • Which is the best description of the difference between bound and unbound forms? O Bound forms are similar to hierarchical forms
    7·1 answer
  • How do you change the text style on brainly mobile ?
    12·1 answer
  • What laptops can you get for 2500$ and should mostly using Microsoft applications.
    14·2 answers
  • How did imperialism lead to WWI? A The debate of the morality of imperialism created tensions around Europe b Native people were
    12·1 answer
  • ---------------------- use of the Internet to access programs and data on computers that are not owned and managed by the user o
    9·1 answer
  • Which command could you use to change to the /usr directory using a relative pathname?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!