How to use newline statement in print function? How to print the color of the object in next line in below code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to use newline statement in print function? How to print the color of the object in next line in below code?

class Robot: def introduce_self(self): print("My name is " + self.name +" My color is "+ self.color) r1 = Robot() r1.name = "Tim" r1.color = " red" r1.weight = 30 r2 = Robot() r2.name = "Alice" r2.color = " blue " r2.weight = 65 r1.introduce_self() r2.introduce_self()

7th Aug 2020, 2:31 AM
Ashish Singh
1 Answer
0
Just take one new print line inside the function, it'll print the statement in new line. Like this: print("My Colour is: " + self.color)
7th Aug 2020, 7:38 AM
Janapriyo Maitra
Janapriyo Maitra - avatar