What is the meaning of !r ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the meaning of !r ?

def __repr__(self): return f'Car({self.color!r},{self.mileage!r})' can anyone tell me what is the meaning !r in this code why people use this in their codes.

7th Oct 2018, 5:01 PM
Maninder $ingh
Maninder $ingh - avatar
1 Answer
+ 2
It tell to python to use the representation (by __repr__()) of corrispective parameter (in this case self.color and self.mileage) for put it in string instead of default string conversion https://docs.python.org/3.1/library/string.html#format-string-syntax
7th Oct 2018, 7:34 PM
KrOW
KrOW - avatar