#๐ Need simple help with an error
17 messages ยท Page 1 of 1 (latest)
@tough obsidian
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
file = input("File name: ")
match file:
case file.endswith('.gif'):
print("image/gif")
i get an TypeError: called match pattern must be a class
i wanted my code to print image/gif if the string file ends with .gif
use an if-statement, not match
use if/elif/else statements for that, not match/case
okay, thank you
match-cases use patterns, not expressions, they do not evaluate to any values so you can't use them exactly like if-statements
match/case is used when you want to test complex conditions that vary based on the object's type
Okay
file = input("File name: ")
if file.endswith('.gif'): # use a simple if-else statement
print("image/gif")
else:
print("Unknown file type") # optionally, handle other file types
@tough obsidian ^^
thank you
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ Need simple help with an error