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
Tamera was responding to a complaint that one of the employees is having problems with the wired network connection on their lap
WARRIOR [948]

Answer:

tamera like from sister sister hehe

Explanation:

sorry i dont know the awnser

3 0
3 years ago
What obstacles could prevent you from getting and keeping a job
stepladder [879]
Drugs, No Collage, Gangs, bad grades, Criminal Records →
7 0
4 years ago
Which of the following could occur when both strong and weak ciphers are configured on a VPN concentrator? (Select TWO) A. An at
Elza [17]

Answer:

A. An attacker could potentially perform a downgrade attack.

E. The IPSec payload reverted to 16-bit sequence numbers.

Explanation:

When both strong and weak ciphers are configured on a VPN concentrator, the following are likely to occur;

An attacker could potentially perform a downgrade attack

The IPSec payload reverted to 16-bit sequence numbers

3 0
3 years ago
How impactful were shipping errors on customer questions.
Bumek [7]

Answer:

It's due to damage of goods

7 0
2 years ago
One of the most common causes of fires in the home and workplace is: a. All of the answer choices b. Arson c. Candle d. Faulty e
solniwko [45]
Electricity is one of the most common causes of fire in homes and workplaces. Electrical accidents appear to be caused by a combination of two factors: 1. Unsafe equipment and/or installation; 2. Workplaces made unsafe by the environment

So the answer would be D)Faulty electricity
8 0
3 years ago
Other questions:
  • ‘The increased availability of mobile digital devices has had a positive impact on how young people use their free time’. Make a
    14·2 answers
  • HELPPP ASAPP
    8·2 answers
  • A user of the wireless network is unable to gain access to the network. The symptoms are:1.) Unable to connect to both internal
    6·1 answer
  • _____ are likely to support bigger government, social welfare programs, and legalized abortion.
    8·2 answers
  • Which of the following is considered to be intellectual property?
    9·1 answer
  • Write a function shampoo_instructions() with parameter num_cycles. If num_cycles is less than 1, print "Too few.". If more than
    9·1 answer
  • You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written?
    10·1 answer
  • Which of the following is most likely to include technical vocabulary?
    7·1 answer
  • How does a security information and event management system (SIEM) in a SOC help the personnel fight against security threats
    13·1 answer
  • RDBMSs enforce integrity rules automatically. <br> a. True<br> b. False
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!