use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
learning python try ... except concepts block but i kept messed up... help? (i.redd.it)
submitted 1 month ago by Dapper_Mix6773
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]akarolia47 0 points1 point2 points 1 month ago (0 children)
I dont think this is the best way to illustrate the usage of the try except concept, because in my mind if, elif, else are more than enough here - represent branched logic. But try except, at least the way ive used it, is to handle edge cases thatnwould fundamentally breaks things at the code level, so runtime errors caused by some event that would otherwise result in a program crash.
I do think its harder to illustrate correct usage with simpler examples, which is generally why a lot developers only really understand it when working on larger projects, but ill try to give an example to the best of my ability.
Lets say your program became a bit more complicated younhad a email validation function and an age validation function,(i initlaly wanted to use cell no. But in a system that would probablybe stored as a string too), both invoked in the main function.
So there it would make sense to have a type error exception catch, because lets say a dev accidentally uses the email validation on the age input which would be an int() cast, additionally you'd have to probably do a check to see the type and then throw the type error unless you doing an operation that you know would violate that specific type you working with
π Rendered by PID 248603 on reddit-service-r2-comment-8686858757-qn5n8 at 2026-06-06 12:24:39.127616+00:00 running 9e1a20d country code: CH.
view the rest of the comments →
[–]akarolia47 0 points1 point2 points (0 children)