When reading python APIs, I found an interesting thing: Function Annotation (Function Annotation) of python)
Original article:
4.7.7. Function Annotations
Function annotations are completely optional, arbitrary metadata information about user-defined functions. Neither Python itself nor the standard library use function annotations any way; this section just shows the syntax. Third-party projects are free to use function annotations documentation, type checking, the attribute of the function as a dictionary have no effect on any other part of the function. Parameter annotations are defined by a colon after the parameter name, followed by an expression evaluating to the value of the annotation. Return annotations are defined by a literal ->, followed by an expression, between the parameter list the colon denoting the end of the statement. The following example has a positional argument, a keyword argument, the >>> f(ham: 42, eggs: int = ) -> (, f.(>>> f(: < >, : , : 42
After a brief look, I did not understand the meaning of the parameters. I wrote the program again:
f(ham: 42, eggs: int = ) -> (, f. ( f()
Running effect:
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32, >>> ================================ RESTART ================================>>>: < >, : 42, : >>>
The running effect is the same as that described in the python API.
After searching some data, we found the parameter meanings:
Let's take a look at several demos:
f(ham: 42 = , eggs: int = ) -> (, f. ( f()
Running effect:
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32, >>> ================================ RESTART ================================>>>: < >, : 42, : >>>
f(ham: = , eggs: int = ) -> (, f. ( f()
Running effect:
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32, >>> ================================ RESTART ================================>>>: < >, : , : >>>
f(ham: = , eggs: str = ) -> (, f. ( f()
Running effect:
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32, >>> ================================ RESTART ================================>>>: < >, : , : >>>
(str == || str.equals("" flag = ( i = 0; i < str.length(); i++ ((str.charAt(i) < 'a' || str.charAt(i) > 'z'&& (str.charAt(i) < 'A' || str.charAt(i) > 'Z'=
Here you probably know what I want to say!
Summary:
f(ham: 42, eggs: int = ) -> (, f.( f(ham: int = 42, eggs: str = ) -> (, f.(