Python Forum

Full Version: [Solved] unkown (to me) function def parm "name1:name2" syntax.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I came across a function definition (inside a class) which has a "name1: name2" part.
def func(self, name1: name2):
Has that "name1: name2" syntax a name? (general searching is a bit tricky on this one)
And I guess: Any particular reasons/benefits for using it.

In case it might matter (probably not). Its used in some python script that is used within an otherwise Java environment.
Is name2 a type, like int or str? This looks like type annotations
(Nov-11-2022, 10:16 AM)buran Wrote: [ -> ]Is name2 a type, like int or str?
No, its some custom class provided by the main application.

(Nov-11-2022, 10:16 AM)buran Wrote: [ -> ]This looks like type annotations
Yea. You just beat me to that one. function-parameter-with-colon
(Nov-11-2022, 10:32 AM)MvGulik Wrote: [ -> ]No, its a custom class
That's also a type, i.e. custom type :-)
>>> class Spam():
...     pass
...
>>> isinstance(Spam, type)
True
(Nov-11-2022, 10:34 AM)buran Wrote: [ -> ]That's also a type, i.e. custom type :-)

Right.
Not sure in that case what else it could have been. Huh
After reading up on type annotations. I think I get the basics of it.
Additional type-check info/syntax for (in this case) the main Java-application that is processing these user script.
Thanks

[SOLVED]