Question

In python, within a class's method, how can I create an attribute (field) named _age and...

In python, within a class's method, how can I create an attribute (field) named _age and initialize its value to 47?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class Person:
    def initialize_age(self):
        self._age = 47

    def get_age(self):
        return self._age


# Testing the function/class here. ignore/remove the code below if not required
person = Person()
person.initialize_age()
print("Age is", person.get_age())

Add a comment
Know the answer?
Add Answer to:
In python, within a class's method, how can I create an attribute (field) named _age and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a Python class named Phonebook with a single attribute called entries. Begin by including a...

    Create a Python class named Phonebook with a single attribute called entries. Begin by including a constructor that initializes entries to be an empty dictionary. Next add a method called add_entry that takes a string representing a person’s name and an integer representing the person’s phone number and that adds an entry to the Phonebook object’s dictionary in which the key is the name and the value is the number. For example: >>> book = Phonebook() >>> book.add_entry('Turing', 6173538919) Add...

  • I am new at prgraming in python and I was wondering how you can create a...

    I am new at prgraming in python and I was wondering how you can create a new line within a print statment. I tried using \n but i keep getting an error

  • Create a Python file (book.py) that has a class named Book. Book class has four attributes,...

    Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...

  • Java Create a class named OrderedList. It will use a LinkedList of integers as its attribute....

    Java Create a class named OrderedList. It will use a LinkedList of integers as its attribute. The constructor will simply create an empty list. This will be a different LinkedList, as all of the items will be in ascending numerical order. That means items will not necessarily be placed at the end of the list, but placed where it should be located. Note that the iterator simply uses the next() method, so if you use the iterator to find the...

  • Create a Python file (book.py) that has a class named Book. Book class has four attributes, title...

    Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...

  • Create another Java class named EmployeeMain within the same project, which includes the main method. a....

    Create another Java class named EmployeeMain within the same project, which includes the main method. a. Include another class named Employee in the same Java file. This class has the following instance variables and instance methods. Define all the instance/static variables with private access modifier and constructors, instance/static methods with public access modifier. Instance Variables empID: int employeeName: String basicSalary: double Constructor Set the value for empID. Instance Methods Get and set methods for all instance variables. displayEmployee: Display the...

  • How can I create a python gooey that will display an image and as well zoom...

    How can I create a python gooey that will display an image and as well zoom in on that image?

  • PYTHON (A voting machine consists of an election district, together with the names of the candidates...

    PYTHON (A voting machine consists of an election district, together with the names of the candidates and the number of votes cast for each candidate. Define a VotingMachine class, wrote a docstring for the class, and define the following three class methods: 1. An initialization method. The initialization method should: * take a string parameter, electionDistrict, and assign it to the instance attribute elctionDistrict of the voting machine being created. * create an instance attribute named candidates for the voting...

  • How can I create a fractal spiral like a fibbonacci spiral in Python without turtle. I...

    How can I create a fractal spiral like a fibbonacci spiral in Python without turtle. I am working with object oriented programming/

  • python 3 inheritance Define a class named bidict (bidirectional dict) derived from the dict class; in...

    python 3 inheritance Define a class named bidict (bidirectional dict) derived from the dict class; in addition to being a regular dictionary (using inheritance), it also defines an auxiliary/attribute dictionary that uses the bidict’s values as keys, associated to a set of the bidict’s keys (the keys associated with that value). Remember that multiple keys can associate to the same value, which is why we use a set: since keys are hashable (hashable = immutable) we can store them in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT