Hi. I uploaded arithmetic_arranger.py to my github repository. It’s for a freecodecamp test. I see Sequence[str] at line 54. Pycharm says they are both classes. I googled for info, found nothing. So, Sequence is acting as a function working on str? How does it work? Thanks ![]()
You didn’t provide a link to your code, but Sequence[str] in Python is usually a type hint, also called an annotation. It may be used like this:
def some_function(x: Sequence[str]):
...
and it means that you’re supposed to pass a sequence of strings as the x parameter to that function. For instance, Python lists are a type of sequence, so you might want to call that function like some_function(["abc", "xyz"]), but not like some_function([123, 789]).
You may want to take a look at some Python typing guides/tutorials to learn more.
- Tutorial from Real Python: Python Type Checking (Guide) – Real Python
- Python
typingmodule reference: typing — Support for type hints — Python 3.11.4 documentation - Cheat sheet from mypy (a type checker that looks at your code and tells you if you are following what the annotations tell you to do): Type hints cheat sheet - mypy 1.3.0 documentation
That helps a lot. Thanks ![]()