Home > other >  Python using format how to output formatted output '{'}' '
Python using format how to output formatted output '{'}' '

Time:10-11

"{{... {}... {} ". The format (' example)
Get the string '{... Example... }
'
 
The class Circle (Point) :
# define Circle structure of a class method (initialization)
Def __init__ (self, x, y, redius) :
The self, super (Circle) __init__ (x, y)
The self. The redius=redius
# custom Circle class object formatted output function (string ())
Def string (self) :
Print (" the graphics initialization point is: {{X: {}, Y: {}}}; {{radius: {}}} ". The format (self) x, the self. The y, the self. The redius))

O
The graphics initialization point is: {X 5, Y: 5}; 8} {radius:

CodePudding user response:

Where did you get the code? First of all, the first, you need to inherit Point class, then the code Point class?
You need inside the constructor of the superclass constructor, also there is an error?

To change the code (remove the part of the parent) :
The class Circle () :
# define Circle structure of a class method (initialization)
Def __init__ (self, x, y, redius) :
Self. X=x
The self. The y=y
The self. The redius=redius
# custom Circle class object formatted output function (string ())
Def string (self) :
Print (" the graphics initialization point is: {{X: {}, Y: {}}}; {{radius: {}}} ". The format (self) x, the self. The y, the self. The redius))

After the execution:

> A=Circle (1,3,5)
> A.s tring ()
The graphics initialization point is: {X: 1, Y: 3}; {radius: 5}

  • Related