Python Forum
[Solved] unkown (to me) function def parm "name1:name2" syntax.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] unkown (to me) function def parm "name1:name2" syntax.
#1
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.
Reply
#2
Is name2 a type, like int or str? This looks like type annotations
ndc85430 likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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
Reply
#4
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(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
Reply
#6
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] Looking for documentation on Reportlab's canvas.transform() function NeilUK 1 1,331 Aug-23-2023, 01:21 PM
Last Post: NeilUK
  [Solved] Import syntax SpongeB0B 1 1,363 Dec-28-2022, 08:37 AM
Last Post: Gribouillis
  meaning of -> syntax in function definition DrakeSoft 5 3,217 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
Star I'm getting syntax error while using input function in def. yecktmpmbyrv 1 2,621 Oct-06-2021, 09:39 AM
Last Post: menator01
  Tuple generator, and function/class syntax quazirfan 3 6,240 Aug-10-2021, 09:32 AM
Last Post: buran
  [Solved] TypeError when calling function Laplace12 2 3,674 Jun-16-2021, 02:46 PM
Last Post: Laplace12
  Function syntax error Changosoyyo 2 2,669 Mar-07-2021, 10:42 PM
Last Post: Changosoyyo
  Syntax Error: Outside a function? aplusfordao2702 2 2,750 Dec-01-2020, 03:25 PM
Last Post: deanhystad
  Invalid syntax on print function DoctorSmiles 2 3,363 Jul-12-2020, 07:39 PM
Last Post: DoctorSmiles
  Function: SyntaxError: invalid syntax vejin 2 2,881 Feb-02-2020, 09:25 PM
Last Post: ThiefOfTime

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020