I am writing a small function; the result must be displayed in multiple lines; how to do this
def display(self):
return f'Name: {self.name},\n Roll no:{self.rollno}'
I am writing a small function; the result must be displayed in multiple lines; how to do this
def display(self):
return f'Name: {self.name},\n Roll no:{self.rollno}'
You can use """
or '''
to start and end a multiline string in Python. Example:
def try_print_this():
return """This is
a multiline
string in Python"""
print(try_print_this())
In your case that should be:
def display(self):
return f'''Name: {self.name},
Roll no:{self.rollno}'''