Exceptions in Python: Types of Errors in Python (Syntax, Logical) - Python Tutorial for Beginners

Опубликовано: 25 Апрель 2021
на канале: Digital Academy
2,159
23

🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!

🖥️ Exceptions in Python: Types of Errors in Python (Syntax Errors, Logical Errors)

You can make certain mistakes while writing a program that lead to errors, when you try to run it. During its execution, Python program terminates as soon as it encounters an error, that is not handled. These errors can be classified into 2 classes:

Syntax errors in Python
Logical errors in Python - also known as Exceptions


○ Syntax Errors in Python

Errors caused by not following the proper structure of the language, are called syntax error - or parsing error. Syntax errors are the most basic type of error. They arise when the Python parser is unable to understand a line of code. Most syntax errors are: typos, incorrect indentation, or incorrect arguments. If you get this error, try looking at your code for any of these: misspelling, missing, or misusing keyword. An arrow indicates where the parser ran into the syntax error.

for action in ["like", "comment", "share"]
^
SyntaxError: invalid syntax


○ Logical Errors in Python (Exceptions)

Errors that occur at runtime - after passing the syntax test - are called Exceptions in Python, or Logical errors in Python. These errors are the most difficult type of errors to find because they will give unpredictable results and may crash your program.

A lot of different things can happen, if it encounters a Logical error. Whenever these types of runtime errors occur, Python will create an Exception object.

Exceptions arise when the python parser knows what to do with this piece of code, BUT is unable to perform this action. e.g Trying to access the Internet without internet connection: the Python interpreter knows what to do with that command, but is unable to perform it.

Illegal operations can raise Exceptions, too. Actually, there are plenty of built-in exceptions that are raised in Python, when the following corresponding errors occur: ValueError, TypeError, ZeroDivisionError, ImportError - and, so many more! Consequently, if not handled properly, Python prints the Traceback of that error. And the last line of this message indicates what type of exception error your program ran into - along with some details about what triggered this error.

for i in [1, 2, 3]:
print(i / 0)

Traceback (most recent call last):
File "stdin", line 2, in module
ZeroDivisionError: division by zero

Fortunately, you can catch and handle all these kind of exceptions, then also adapt your program so it does not crash. You can also define your own exceptions in Python, when required!

After seeing the differences between Syntax errors and Exceptions in Python, Let's move forward and discover multiple ways to RAISE, CATCH and HANDLE Exceptions in Python.

Let's play this video, stick around and watch until the end of this video! 👍🏻

Digital Academy™ 🎓

***

☞ WATCH NEXT:
○ Data Types in Python -    • DATA TYPES in Python (Numbers, String...  
○ Operators in Python -    • OPERATORS in Python (Arithmetic, Assi...  
○ IF Statements in Python -    • CONDITIONAL Statements in Python (IF,...  
○ FOR Loops in Python -    • FOR Loop in Python (Syntax, Break, Co...  

📖 Blog: http://digital.academy.free.fr/blog

📖 [FULL Course] HOW TO Learn Python? Python Tutorial for Beginners:    • 🐍 Python 101: Learn Python Basics for...  

📖 [PLAYLIST] Complete Python Development Course for Beginners: http://digital.academy.free.fr/playli...

🧑‍🎓 [COURSE] http://digital.academy.free.fr/courses

📘 [BOOK] Python for Absolute Beginners: https://amzn.to/3NvyOWV

🛒 Shopping and Discounts: http://digital.academy.free.fr/store

💌 Weekly Newsletter for Developers: https://www.getrevue.co/profile/digit...

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡
✧ http://digital.academy.free.fr/
✧   / digitalacademyy  
✧   / digitalacademyfr  
✧   / digital_academy_fr  
✧    / digitalacademyonline  

♡ SUPPORT US ♡
✧ http://digital.academy.free.fr/join
✧ http://digital.academy.free.fr/store
✧ http://digital.academy.free.fr/donate
✧ http://digital.academy.free.fr/subscribe
✧   / digital_academy  
✧ https://www.buymeacoffee.com/digital_...

***


Смотрите видео Exceptions in Python: Types of Errors in Python (Syntax, Logical) - Python Tutorial for Beginners онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Digital Academy 25 Апрель 2021, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 2,159 раз и оно понравилось 23 людям.