From the course: Python for JavaScript Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Why try/except is everywhere

Why try/except is everywhere - Python Tutorial

From the course: Python for JavaScript Developers

Start my 1-month free trial

Why try/except is everywhere

- [Instructor] JavaScript has a try-catch syntax but we just don't see it so often. Python on the other hand uses try-except extensively. Take a look at this code in O3_O4.js. This is JavaScript on lines one to three, we define an object that has a title and the title is JavaScript is great. And then on line six, we check if the article has an author, if it does, which it doesn't, we console log the author on line six, otherwise on line nine we console log anonymous author. So here we basically use if on line six to ask for permission. And then when we don't have that permission, we go on to say anonymous author. Python has a different approach, it says, ask for forgiveness when you can. What do I mean by that? Take a look at this code in O3_O4.pi. We define an article. Now, keep in mind this is a dictionary not an object meaning it's going to behave slightly different. And then on line five, we print the articles…

Contents