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
Select the correct answer from each drop-down menu.
Dmitry_Shevchenko [17]

Answer:

Suzanne needs a blog

Explanation:

Because she wants to use a digital media tool that acts as a journal and facilitates discussion, Suzanne would need a blog for this.

A blog is a platform where people can meet and have discussions on the internet sometimes in a diary-like format.

Suzanne would need software like WordPress for her blog.

8 0
3 years ago
Trisha is looking for a new table style. What is the fastest way for her to preview how different styles in the gallery would lo
Elena-2011 [213]

Answer: The correct answer is to hover the cursor over the different styles in the gallery.

Explanation: The fastest way to preview the different styles in the style gallery is to hover the cursor over each style. This will preview the style, without making the permanent change so that you can see how it looks without changing to each individual style.

4 0
3 years ago
Instead of sending an entire file in one big chunk across the​ Internet, __________ is used which dices the file up into little
azamat

Answer:

TCP/IP

Explanation:

TCP/IP which stands for Transmission Control Protocol and Internet Protocol are network protocols which divide your message into smaller chunks or fragments known as network packets and sends them out onto the Internet. When the chunks arrive at the intended destination, TCP/IP on the receiving end reassembles the network packets into the original message.

TCP/IP are the main protocols used for sending data over the internet.

7 0
3 years ago
Remembering on which continent 5 different countries are located
Illusion [34]

Answer:

South america.

Explanation:

8 0
3 years ago
The use of computers in education is referred to as computer assisted instruction (CAI). Write a program that will help an eleme
dybincka [34]
I don't think some will write the whole program here, but which part are you having trouble with?
6 0
3 years ago
Other questions:
  • Laura is photographing her son’s baseball game. What ISO setting should she use?
    11·1 answer
  • When should recursion be avoided?
    9·1 answer
  • 9. Which of the following is the most popular eSport game ever?
    13·1 answer
  • Which one way in which using infrared in game console controllers could affect the experience of a person playing the game?
    8·1 answer
  • Write a function longer_string() with two string input parameters that returns the string that has more characters in it. If the
    5·1 answer
  • What is the output of this program? Assume the user enters 2, 5, and 10.
    6·1 answer
  • What makes a source credible?
    9·2 answers
  • 6.What does transgenic mean?​
    12·2 answers
  • Today's manufacturing workplace is most likely to include
    8·1 answer
  • Explain why you do not need expensive equipment to take pictures or record video?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!