Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
making : optional
#4
i didn't think about slices although a different language could require tuples be inside () and use , in place of : in the square brackets. i was thinking about the : that follow keywords like def, if, else, for, while, try. except ... well, eventually follow. what if that language looked like:
class GetItem
    def __class_getitem__(self, key)
        if isinstance(key, slice)
            print("Key is a slice")
        elif isinstance(key, tuple)
            print("Key is a tuple")
            if all(isinstance(item, slice) for item in key)
                print("All items are slices")
            elif any(isinstance(item, slice) for item in key)
                print("One or more items are a slice instance")
        else
            print("Got something else")
        return key
...
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
making : optional - by Skaperen - Apr-04-2021, 10:45 PM
RE: making : optional - by Gribouillis - Apr-05-2021, 09:52 AM
RE: making : optional - by DeaD_EyE - Apr-05-2021, 01:24 PM
RE: making : optional - by Skaperen - Apr-06-2021, 06:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  making : optional Skaperen 3 1,845 Jun-25-2021, 12:13 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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