Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is !r called?

Tags:

python

syntax

I am seeing this for the first time. I wanted to know what the !r in the last line of the code called so that I can search about it. I found this piece of code on: https://adamj.eu/tech/2020/08/10/a-guide-to-python-lambda-functions/

class Puppy:
    def __init__(self, name, cuteness):
        self.name = name
        self.cuteness = cuteness

    def __repr__(self):
        return f"Puppy({self.name!r}, {self.cuteness!r})"
like image 717
Canute S Avatar asked Aug 18 '20 19:08

Canute S


People also ask

Why is it called R?

The "R" name is derived from the first letter of the names of its two developers, Ross Ihaka and Robert Gentleman, who were associated with the University of Auckland at the time.

What is R language called?

R is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S.

What is R known for?

R offers a wide variety of statistics-related libraries and provides a favorable environment for statistical computing and design. In addition, the R programming language gets used by many quantitative analysts as a programming tool since it's useful for data importing and cleaning.

What does \r represent?

\r is a carriage return which often means that the cursor should move to the leftmost column, while \n is a line feed which moves the cursor to the next line.


1 Answers

It's a format string conversion flag that tells the formatter to call repr on the object before formatting the string.

Three conversion flags are currently supported: '!s' which calls str() on the value, '!r' which calls repr() and '!a' which calls ascii().

like image 189
kojiro Avatar answered Sep 23 '22 00:09

kojiro