[Solved] unkown (to me) function def parm "name1:name2" syntax. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: [Solved] unkown (to me) function def parm "name1:name2" syntax. (/thread-38678.html) |
[Solved] unkown (to me) function def parm "name1:name2" syntax. - MvGulik - Nov-11-2022 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. RE: unkown (to me) function def parm "name1:name2" syntax. - buran - Nov-11-2022 Is name2 a type, like int or str ? This looks like type annotations
RE: unkown (to me) function def parm "name1:name2" syntax. - MvGulik - Nov-11-2022 (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 annotationsYea. You just beat me to that one. function-parameter-with-colon RE: unkown (to me) function def parm "name1:name2" syntax. - buran - Nov-11-2022 (Nov-11-2022, 10:32 AM)MvGulik Wrote: No, its a custom classThat's also a type, i.e. custom type :-) >>> class Spam(): ... pass ... >>> isinstance(Spam, type) True RE: unkown (to me) function def parm "name1:name2" syntax. - MvGulik - Nov-11-2022 (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. RE: unkown (to me) function def parm "name1:name2" syntax. - MvGulik - Nov-11-2022 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] |