What will be the output of the following Python code?
class Name:
def __init__(self, firstName, mi, lastName):
self.firstName = firstName
self.mi = mi
self.lastName = lastName
firstName = "John"
name = Name(firstName, 'F', "Smith")
firstName = "Peter"
name.lastName = "Pan"
print(name.firstName, name.lastName)
class Name:
def __init__(self, firstName, mi, lastName):
self.firstName = firstName
self.mi = mi
self.lastName = lastName
firstName = "John"
name = Name(firstName, 'F', "Smith")
firstName = "Peter"
name.lastName = "Pan"
print(name.firstName, name.lastName)
A. Peter Pan
B. John Pan
C. Peter Smith
D. John Smith
Answer: Option B
Related Questions on Strings in Python
Which of the following is the correct way to create a string in Python?
A. "Hello, World!"
B. 'Hello, World!'
C. "Hello, World!'
D. 'Hello, World!"
What does the len() function do when applied to a string?
A. Returns the length of the string
B. Converts the string to lowercase
C. Converts the string to uppercase
D. Removes leading whitespace
Which character is used to access individual elements of a string by index in Python?
A. . (period)
B. , (comma)
C. : (colon)
D. [ and ] (square brackets)
Join The Discussion