Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133582734
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 10, Problem 5SA
Explanation of Solution
“__init__” method:
- • It is a special method in Python class.
- • This method is automatically executed when the instance of the class is created in the memory.
- • This method is most commonly known as the initializer method.
- • This method initializes the object’s data attributes.
- • The method name should start with two underscores and end with two underscores.
Purpose of “self” parameter:
- • It is required in every method of a class.
- • This parameter refers to the specific object that the method operates on.
- • It must be present in a method.
- • It is automatically assigned to the object that was just created.
Example:
#define the class Emp_class
class Emp_class:
#defined the init method
def __init__(self, name, salary):
#assign name
self.name = name
#assign salary
self...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The first parameter in the initializer method is named self by convention. What is the role of self?
What type must self be for the __str__ method?
When passing an object type as parameter, changing formal parameter __ change actual parameter
a. will
b. will not
Chapter 10 Solutions
Starting Out with Python (3rd Edition)
Ch. 10.2 - You hear someone make the following comment: "A...Ch. 10.2 - In this chapter, we use the metaphor of a cookie...Ch. 10.2 - What is the purpose of the _ _init_ _ method? When...Ch. 10.2 - Prob. 8CPCh. 10.2 - In a Python class, how do you hide an attribute...Ch. 10.2 - What is the purpose of the _ _str_ _ method?Ch. 10.2 - Prob. 11CPCh. 10.3 - What is an instance attribute?Ch. 10.3 - Prob. 13CPCh. 10.3 - What is an accessor method? What is a mutator...
Ch. 10.4 - What is an object?Ch. 10.4 - Prob. 2CPCh. 10.4 - Why is an object's internal data usually hidden...Ch. 10.4 - What are public methods? What are private methods?Ch. 10.4 - Prob. 15CPCh. 10.4 - Prob. 16CPCh. 10.4 - When designing an object-oriented application, who...Ch. 10.4 - How do you identify the potential classes in a...Ch. 10.4 - What are a classs responsibilities?Ch. 10.4 - What two question should you ask to determine a...Ch. 10.4 - Will all of a class's action always be directly...Ch. 10 - The _______ programming practice is centered on...Ch. 10 - The ___________ programming practice is centered...Ch. 10 - A(n) _____ is a component of a class that...Ch. 10 - Prob. 4MCCh. 10 - By doing this, you can hide a classs attribute...Ch. 10 - Prob. 6MCCh. 10 - A(n) ________ method stores a value in a data...Ch. 10 - Prob. 8MCCh. 10 - If a class has a method named _ _str_ _ , which of...Ch. 10 - A set of standard diagrams for graphically...Ch. 10 - In one approach to identifying the classes in a...Ch. 10 - Prob. 12MCCh. 10 - The practice of procedural programming is centered...Ch. 10 - Object reusability has been a factor in the...Ch. 10 - It is a common practice in object-oriented...Ch. 10 - Prob. 4TFCh. 10 - Starting an attribute name with two underscores...Ch. 10 - You cannot directly call the _ _ str _ _ method.Ch. 10 - One way to find the classes needed for an...Ch. 10 - Prob. 1SACh. 10 - Why should an object's data attributes be hidden...Ch. 10 - What is the difference between a class and an...Ch. 10 - The following statement calls an object's method....Ch. 10 - Prob. 5SACh. 10 - In a Python class, how do you hide an attribute...Ch. 10 - Prob. 7SACh. 10 - Suppose my_car is the name of a variable that...Ch. 10 - Prob. 2AWCh. 10 - Look at the following description of a problem...Ch. 10 - Pet Class The Pet class Write a class named Pet,...Ch. 10 - Car Class Write a class named Car that has the...Ch. 10 - Personal Information Class Design a class that...Ch. 10 - Employee Class Write a class named Employee that...Ch. 10 - RetailItem Class Write a class named RetailItem...Ch. 10 - Employee Management System This exercise assumes...Ch. 10 - Cash Register This exercise assumes you have...Ch. 10 - Trivia Game In this programming exercise, you will...
Knowledge Booster
Similar questions
- User Class NOTE: The important method has been ATTRIBUTES given to you. userld:int //generates unique id from 10001 upwards INSTRUCTION 1 username:string firstname:string lastname:string dob:string The program should generate unique userld whenever new object is created. Notice that idGenerator is static variable, so assign the current value of idGenerator age: int idGenerator: static int; to userld, so that each user will have totalUsers : static int МЕТНODS User() User(string, string, string, int) User(const User&) "User() unique user id (Starting from 10001). Then increment idGenerator by 1. INSTRUCTION 2 The totalUsers is also a static variable. This should keep track of the total users in the class. With the Above UML for CLASS USER, answer the following questions 1. Complete or Create the default constructor method. a. The default constructor should accept just the firstname, lastname, dob (date of birth) and age from the keyboard. b. Write a setter method that sets the username…arrow_forwardTrue or False If a method belongs to a class, then you must write a method’s definition inside the class.arrow_forwardWhen implementing a method, use the class's accessor and mutator methods to access the class data. O static O public O private O protectedarrow_forward
- The __________ declares that a derived class is allowed to override a method. a. void keyword b. protected keyword c. base keyword d. virtual keywordarrow_forwardjava Assignment Description: Write a class named Car that has the following fields: The yearModel field is an int that holds the car’s year model. The make field references a String object that holds the make of the car. The speed field is an int that holds the car’s current speed. In addition, the class should have the following constructor and other methods. The constructor should accept the car’s year and make as arguments. These values should be assigned to the object’s yearModel and make fields. The constructor should also assign 0 to the speed field. Constructor: The constructor should accept no arguments. Constructor: The constructor should accept the car’s year as argument.Assign the value to the object’s yearModel. No need to assign anything to the make and assign 0 to speed. Appropriate mutator methods should set the values in an object’s yearModel, make, and speed fields. Appropriate accessor methods should get the values stored in an object’s yearModel, make, and…arrow_forwardT/F: Instance variables are shared by all the instances of the class. T/F: The scope of instance and static variables is the entire class. They can be declared anywhere inside a class. T/F: To declare static variables, constants, and methods, use the static modifier.arrow_forward
- in c# i need to Create a BankAccount class with the following properties: Account Number (string)Account Holder Name (string)Balance (double)Account Type (enum: Savings, Current)Create the following methods in the BankAccount class: Deposit(double amount): Method to deposit money into the accountWithdraw(double amount): Method to withdraw money from the accountCheckBalance(): Method to check the current balance of the account I am getting a error in pic my code is // Define an enumeration type for bank account typespublic enum AccountType{ Savings, Current} // Define a class for bank accountspublic class BankAccount{ // Properties for the account number, account holder name, balance and account type public string AccountNumber { get; set; } public string AccountHolderName { get; set; } public double Balance { get; set; } public AccountType AccountType { get; set; } // Method to deposit money into the account public void Deposit(double amount) {…arrow_forwardQuestion - Create a class named Pizza with the following data fields: description - of type String price - of type double The description stores the type of pizza (such as sausage and onion). Include a constructor that requires arguments for both fields and a method named display to display the data. For example, if the description is 'sausage and onion' and the price is '14.99', the display method should output: sausage and onion pizza Price: $14.99 Create a subclass named DeliveryPizza that inherits from Pizza but adds the following data fields: deliveryFee - of type double address - of type String The description, price, and delivery address are required as arguments to the constructor. The delivery fee is $3 if the pizza ordered costs more than $15; otherwise it is $5. Code that is not accepted - class DeliveryPizza extends Pizza { private double deliveryFee; private String address; public DeliveryPizza(String desc, double price, double deliveryFee, String address){…arrow_forwardIn java languagearrow_forward
- #pyhton programing topic: Introduction to Method and Designing class Method overloading & Constructor overloading ------------------ please find the attached imagearrow_forwardIn C#, How would you compile the necessary code to define a class that will store a point in space. It will need the following data members: xcoord, ycoord. Include the following methods:- a default constructor that will set the coordinates to 0,0- a constructor that takes two values corresponding to the xcoord and ycoord values and sets them accordingly- accessor methods to get and set the values of the coordinates (you can use properties if you wish)- a display constructor that returns a string in the format of (xcoord, ycoord) Usage of the class: //create an instance of 2 points Point myPoint = new Point; //assign values using properties |If you do not declare properties for the data items, you might do the following myPoint.Xcoord = 42; |myPoint.SetX(42); myPoint.Ycoord = 19.63; |myPoint.SetY(19.63) // use the Display() method WriteLine(“The point is “+myPoint.Display()); //output The point…arrow_forwardOverriding a method is defined as the ability to override the default method.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT