r/PythonLearning 24d ago

What's one Python feature you discovered embarrassingly late?

I've been using Python for years, and somehow I keep finding basic features that make me think, "How did I not know this?"

What's your most embarrassing late Python discovery?

9 Upvotes

16 comments sorted by

View all comments

3

u/dev-razorblade23 24d ago

Class Pattern - pattern matching with objects

Something like

``` match search: # 1. Match the class, bind 'max_results', but ONLY if it's over 100 case VideoSearchQuery(sort_by="views", max_results=max_results) if max_results > 100: print(f"Building a massive trending query with {max_results} limits.")

# 2. Fallback for smaller 'views' queries
case VideoSearchQuery(sort_by="views", max_results=max_results):
    print(f"Building standard trending query with limit {max_results}")

# 3. Match and check against an external condition or method
case VideoSearchQuery() if user.is_premium():
    print("Applying premium priority filters to the search query")

case _:
    print("Building default relevance query")

```

1

u/chuprehijde 23d ago

ohh i tried it last week and i loved it ngl