
Bryce H.
asked 02/25/23how to code in python?
Create a new class called Person. Add 3 attributes (or fields) called first_name, middle and last_name.
Add a function called format_name() and return all 3 attributes.
(Hint: Use the same function we wrote in week 6).
Create a new instance of the Person class, set the attribute fields and then call the format_name() function using print().
3 Answers By Expert Tutors
William M. answered 05/31/23
Computer/HS Instructor w/7+ years teaching Computer Science

William M.
05/31/23

Brooke R. answered 04/05/23
Princeton PhD Student | M.S. in Computer Science | Frmr SWE @ Blizzard
Here's some example code that creates the Person
class with the given attributes and method, creates an instance of the class, sets the attribute fields, and calls the format_name()
method to print the full name of the Person:
In this code, the __init__
method is used to define the constructor for the Person
class, which takes three parameters: first_name
, middle_name
, and last_name
. These parameters are assigned to instance variables of the same names using self.first_name = first_name
, self.middle_name = middle_name
, and self.last_name = last_name
.
The format_name
method is defined to return the formatted name string by concatenating the first, middle, and last names.
Then, an instance of the Person
class is created with the line Person("John", "Jacob", "Jingleheimer Schmidt")
, and the format_name
method is called on this instance using person.format_name()
to print the formatted name.
Try running this code yourself to see what happens!

Mehmet D. answered 02/26/23
5-STAR MATH, STATISTICS, COMPUTER SCIENCE/CODING TUTOR!
This is not a place to get your question solved for you. If you have a specific question about something you don't seem to understand, you can ask that. Otherwise, we are not here to do your homework for you.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Salena G.
Hi Bryce! We can schedule a short lesson about this, I can get you where you want, thanks!02/26/23