Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use a class type in it
#1
Hello,
I want to use a description for my parameter of my class method and that give this
class Player:
    def __init__(self, name: str) -> None:
        self.name = name

    def battle(self, opponent: Player) -> int:
        print(f"Battle betwen {self.name} and {opponent.name}")
        return 0
(It's the :Player who don't work)
If anyone have an idea.
Thanks in advance.
Reply
#2
Use : "Player" instead of : Player.
MathisDELAGE likes this post
Reply
#3
(Jan-28-2023, 11:19 PM)Gribouillis Wrote: Use : "Player" instead of : Player.

Ok it work now
Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  search a list or tuple for a specific type ot class Skaperen 8 1,854 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  Python generics: How to infer generic type from class attribute? Thoufak 0 2,770 Apr-25-2021, 09:31 AM
Last Post: Thoufak
  Type hinting - return type based on parameter micseydel 2 2,426 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Object and type class Uchikago 2 2,201 Jul-28-2019, 10:35 AM
Last Post: DeaD_EyE
  Error Type: <class 'OSError'> And Error Type: <class 'ValueError'> runnerpaul 1 3,636 Jul-18-2017, 03:08 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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