[Tutor] Is the use of -> usual in Python?
Mats Wichmann
mats at wichmann.us
Wed Feb 3 19:44:55 EST 2021
On 2/3/21 5:25 PM, Phil wrote:
> |The following is a snippet from a class that I came across yesterday.
> I'm not familiar with the use of "->" in Python code. Is it usual
> practice? Nothing showed up during an Internet search. |
> ||def receive(self) -> str: line =
> self.serial.read_until(self.TERMINATOR) return
> line.decode('UTF8').strip() def send(self, text: str) -> bool: line =
> '%s\r\f' % text self.serial.write(line.encode('|UTF8'))|# the line
> should be echoed. # If it isn't, something is wrong. return text ==
> self.receive() | |-- Regards,
> Phil
It's the function annotation syntax (actunally not just for functions).
It's a runtime no-op i.e. the Python interpreter ignores it, but
type-aware static checkers understand it. Search for something like
"python type hints" to get more info.
More information about the Tutor
mailing list