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
Apple was a pioneer in user interface development, introducing the _____, complete with mouse and screen icons, in the early 198
KiRa [710]

Answer:

The answer is "Option b"

Explanation:

The graphical UI is a kind of user interface, which is used in apple technology. It enables the consumers to use graphic symbols and the main symbol sound signal to communicate with electronic devices rather of text-based consumer interface, type tag commands or code navigation, and wrong option can be described as follows:

  • Option a and Option c both were wrong because the command-line interface is a text-based program, and binary line access via command line.
  • In option d, It is a text-based command, that is used to intact with the user, that's why it is wrong.
7 0
3 years ago
Is it true that if the user log out the computer will turn off automatically​
sergiy2304 [10]
Yes that is a true statement
8 0
3 years ago
Read 2 more answers
When seeking information on the Internet about a variety of subjects, the most
liq [111]

Answer:

wikipedia

Explanation:

they have like almost everything.

6 0
4 years ago
Read 2 more answers
In QBasic, create a number guessing challenge. Your program should generate a random number from 1-
Sergio039 [100]

Answer:

yes

Explanation:

6 0
3 years ago
WHAT DOES THE SCRATCH CODE BELOW DO?
Vinil7 [7]
I think it’s b vertically
7 0
3 years ago
Other questions:
  • A pacing calendar is provided to students so they can:
    8·2 answers
  • What option is used to combine several objects so that they can be treated as a single unit
    6·1 answer
  • The ____ command displays the last 10 lines of a text file.
    5·1 answer
  • Phoebe has to give a permission about recycling. Where should she look while presenting?
    11·1 answer
  • Methods inherited from the base/super class can be overridden. This means changing their implementation; the original source cod
    5·1 answer
  • Is it necessary that every autonomous system use the same intra-AS routing algorithm? Why or why not?
    10·1 answer
  • If a citation has a volume, title, and page numbers, it is a:
    9·2 answers
  • Which computers accuracy is much higher(i.e.analog &amp; digital )​
    14·1 answer
  • In a relational database, information is organized into tables in which each row represents a(n ) ________. Group of answer choi
    6·1 answer
  • Why is quantum computing potentially a better fit for weather forecasting than classical computers?.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!