

{"id":6264,"date":"2018-01-22T11:50:13","date_gmt":"2018-01-22T06:20:13","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=6264"},"modified":"2026-04-24T14:17:24","modified_gmt":"2026-04-24T08:47:24","slug":"python-exception","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-exception\/","title":{"rendered":"What is Python Exception &#8211; Python Error &amp; In-built Exception in Python"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2165,&quot;href&quot;:&quot;https:\\\/\\\/docs.python.org\\\/3\\\/tutorial\\\/errors.html&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251011232041\\\/https:\\\/\\\/docs.python.org\\\/3\\\/tutorial\\\/errors.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 00:33:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-24 14:54:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-28 13:37:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-03 16:57:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 14:09:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 04:36:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 07:20:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-16 06:53:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-19 20:39:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-03 18:38:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-07 12:34:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-24 04:06:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-12 05:18:19&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-29 13:01:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-05 15:02:09&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-05 15:02:09&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<h3>1. Python Error &#8211; Objective<\/h3>\n<p>In this Python Error tutorial, we will discuss what a syntax error in Python is. Along with this, we will study Python exceptions, error messages, and come in-built exception in the Python Programming Language.<\/p>\n<p>It will cover all possible Python errors and Python exceptions to help you run your Python code smoothly, as there are many <strong><a href=\"https:\/\/data-flair.training\/blogs\/reasons-why-should-i-learn-python\/\">reasons why to learn Python<\/a><\/strong>.<\/p>\n<p>So, let&#8217;s begin with Python Error and Python Exception.<\/p>\n<div id=\"attachment_6267\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6267\" class=\"wp-image-6267 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions.jpg\" alt=\"What is Python Error - Python Exception Message &amp; In-built Exception \" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-6267\" class=\"wp-caption-text\">What is Python Error &#8211; Python Exception Message &amp; In-built Exception<\/p><\/div>\n<h3>2. Syntax Errors in Python<\/h3>\n<p>In your code, when you mess up the rules of<strong> <a href=\"https:\/\/data-flair.training\/blogs\/python-syntax-semantics\/\">Python Syntax<\/a><\/strong>, your code doesn\u2019t run.<\/p>\n<p><strong>Common causes of syntax errors:<\/strong><\/p>\n<ul>\n<li><strong>Missing colons:<\/strong> After every flow statement, like if, while, for loops, colons (:) are used to define the indented block, like in functions, loops and in conditionals.<\/li>\n<li><strong>Wrong indentation:<\/strong> Python uses indentation to define the structure of the code blocks.<\/li>\n<li>Syntax errors can occur due to the wrong use of keywords or because of keywords being misspelt.<\/li>\n<\/ul>\n<p>The following code causes a syntax error.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; if 2&gt;1 print(\"2\")<\/pre>\n<p>SyntaxError: invalid syntax<\/p>\n<p>This code doesn\u2019t run because it misses a colon after the condition 2&gt;1.<\/p>\n<p>A syntax error, also called a parsing error, displays \u2018Syntax Error: invalid syntax\u2019.<\/p>\n<h3>3. What is a Python Exception?<\/h3>\n<p>It may be convenient to recognise the problems in your Python code before you put it to real use. But that does not always happen. Sometimes, problems show up when you run the code; sometimes, midway through that.<\/p>\n<p>A Python exception is an error that\u2019s detected during execution. It may be fatal for the program, but not necessarily so. Let\u2019s take the most common example.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a,b=1,0\r\n&gt;&gt;&gt; print(a\/b)<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#208&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>print(a\/b)<\/p>\n<p>ZeroDivisionError: division by zero<\/p>\n<p>Throughout our Python tutorials so far, you\u2019ve noticed words like TypeError, NameError, and so on. It\u2019s time to find out what that is. Also, learn <a href=\"https:\/\/data-flair.training\/blogs\/exception-handling-in-python\/\"><strong>Exception Handling in Python for Python Programming<\/strong>.<\/a><\/p>\n<h3>4. Python Error and Python Exception Message<\/h3>\n<p>When Python errors and exceptions occur, it prints a four-line message on the screen if not handled.<\/p>\n<p>The first line declares that this is a traceback. This means that the interpreter traces the Python exception back to its source.<\/p>\n<p>The second tells us the line number for the code that caused the Python exception. In our case, it is line 1. #208 means this is the 208<sup>th<\/sup> statement we\u2019re running in the interpreter since we opened it.<\/p>\n<p>The third line tells us which line (the statement that) caused the Python exception.<\/p>\n<p>Finally, the fourth line tells us the type of Python exception that occurred. This is accompanied by a short description of what happened.<\/p>\n<h3>5. In-built Python Exception<\/h3>\n<p>Now that we know what an exception is, we will talk about a list of Python exceptions that are built into Python. As you read the list, try to recall if you ever encountered any of these Python exceptions. Tell us in the comments.<\/p>\n<h4><strong>1. AssertionError in Python<\/strong><\/h4>\n<p>This Python exception raises when an assert statement fails. This is also called a Python raise expression.<\/p>\n<p>A successful assert statement looks like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; assert(1==1)<\/pre>\n<p>But when we write the following code, we get an AssertionError:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; assert(1==2)<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#213&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>assert(1==2)<\/p>\n<p>AssertionError<\/p>\n<p>We\u2019ll take the assert statement in detail in a future lesson.<\/p>\n<h4><strong>2. AttributeError in Python<\/strong><\/h4>\n<p>This one occurs when an attribute assignment or reference fails. As an example, let\u2019s take a class<\/p>\n<p>\u2018fruit\u2019.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class fruit:<\/pre>\n<p>pass<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; fruit.size<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#223&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>fruit.size<\/p>\n<p>AttributeError: type object &#8216;fruit&#8217; has no attribute &#8216;size&#8217;<\/p>\n<p>Here, the attribute size does not exist. Hence, it raises an AttributeError.<\/p>\n<h4><strong>3. EOFError in Python<\/strong><\/h4>\n<p>This Python exception raises when the input() function reaches the end-of-file condition.<\/p>\n<h4><strong>4. FloatingPointError in Python<\/strong><\/h4>\n<p>When a floating-point operation fails, this Python error occurs.<\/p>\n<h4><strong>5. GeneratorExit in Python<\/strong><\/h4>\n<p>This raises when a generator\u2019s close() method is called.<\/p>\n<h4><strong>6. ImportError in Python<\/strong><\/h4>\n<p>When the imported module isn\u2019t found, an ImportError occurs.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; from math import ppi<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#234&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>from math import ppi<\/p>\n<p>ImportError: cannot import name &#8216;ppi&#8217;<\/p>\n<h4><strong>7. IndexError in Python<\/strong><\/h4>\n<p>When you access an index on a sequence that is out of range, you get an IndexError.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list=[1,2,3]\r\n&gt;&gt;&gt; list[3]<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#236&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>list[3]<\/p>\n<p>IndexError: list index out of range<\/p>\n<h4><strong>8. KeyError in Python<\/strong><\/h4>\n<p>This raises when a key isn\u2019t found in a dictionary.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dict1={1:1,2:2}\r\n&gt;&gt;&gt; dict1[3]<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#239&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>dict1[3]<\/p>\n<p>KeyError: 3<\/p>\n<h4><strong>9. KeyboardInterrupt in Python<\/strong><\/h4>\n<p>This one occurs when the user hits the interrupt key (Ctrl + C).<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; while True: print(\"Hello\")\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello\r\nHello<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#244&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>while True: print(&#8220;Hello&#8221;)<\/p>\n<p>KeyboardInterrupt<\/p>\n<h4><strong>10. MemoryError in Python<\/strong><\/h4>\n<p>This raises when an operation runs out of memory.<\/p>\n<h4><strong>11. ModuleNotFoundError in Python<\/strong><\/h4>\n<p>When you import a module that does not exist, you will get the ModuleNotFoundError.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; import maths<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#233&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>import maths<\/p>\n<p>ModuleNotFoundError: No module named &#8216;maths&#8217;<\/p>\n<h4><strong>12. NameError in Python<\/strong><\/h4>\n<p>A NameError occurs when a name isn\u2019t found in a scope.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; eggs<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#245&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>eggs<\/p>\n<p>NameError: name &#8216;eggs&#8217; is not defined<\/p>\n<h4><strong>13. NotImplementedError in Python<\/strong><\/h4>\n<p>An abstract method raises a NotImplementedError.<\/p>\n<h4><strong>14. OSError in Python<\/strong><\/h4>\n<p>Now this one is raised when a system operation causes a system-related error.<\/p>\n<h4><strong>15. OverflowError in Python<\/strong><\/h4>\n<p>This raises when the result of an arithmetic operation is too large to be represented.<\/p>\n<h4><strong>16. ReferenceError in Python<\/strong><\/h4>\n<p>This is raised when a weak reference proxy is used to access a garbage-collected referent.<\/p>\n<h4><strong>17. RuntimeError in Python<\/strong><\/h4>\n<p>When an error does not fall under any specific category, we call it a RuntimeError.<\/p>\n<h4><strong>18. StopIteration in Python<\/strong><\/h4>\n<p>The next() function raises StopIteration to indicate that no further items are to be returned by the iterator.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; def countdown():\r\n         n=4\r\n         while(n&gt;0):\r\n                 yield n\r\n                 n-=1\r\n\r\n&gt;&gt;&gt; c=countdown()\r\n&gt;&gt;&gt; next(c)<\/pre>\n<p>4<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; next(c)<\/pre>\n<p>3<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; next(c)<\/pre>\n<p>2<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; next(c)<\/pre>\n<p>1<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; next(c)<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#23&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>next(c)<\/p>\n<p>StopIteration<\/p>\n<h4><strong>19. IndentationError in Python<\/strong><\/h4>\n<p>An IndentationError raises on incorrect indentation.<\/p>\n<h4><strong>20. TabError in Python<\/strong><\/h4>\n<p>When the indentation is inconsistent in tabs and spaces, there\u2019s a TabError.<\/p>\n<h4><strong>21. SystemError in Python<\/strong><\/h4>\n<p>When the interpreter detects an internal error, it\u2019s a SystemError.<\/p>\n<h4><strong>22. SystemExit in Python<\/strong><\/h4>\n<p>The sys.exit() function raises this one.<\/p>\n<h4><strong>23. TypeError in Python<\/strong><\/h4>\n<p>When you apply a function or an operation to an object of the incorrect type, you get a TypeError.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; '10'+10<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#38&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>&#8217;10&#8217;+10<\/p>\n<p>TypeError: must be str, not int<\/p>\n<h4><strong>24. UnboundLocalError in Python<\/strong><\/h4>\n<p>You get an UnboundLocalError when you try to access a local variable without first assigning a value to it.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; def sayhi():\r\n        m+=1\r\n        print(m)\r\n&gt;&gt;&gt; sayhi()<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#53&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>sayhi()<\/p>\n<p>File &#8220;&lt;pyshell#52&gt;&#8221;, line 2, in sayhi<\/p>\n<p>m+=1<\/p>\n<p>UnboundLocalError: local variable &#8216;m&#8217; referenced before assignment<\/p>\n<h4><strong>25. UnicodeError in Python<\/strong><\/h4>\n<p>When a Unicode-related encoding\/decoding error occurs, you get the UnicodeError exception.<\/p>\n<h4><strong>26. UnicodeEncodeError in Python<\/strong><\/h4>\n<p>This is a Unicode error during encoding.<\/p>\n<p><strong>Learn:<\/strong> <strong><a href=\"https:\/\/data-flair.training\/blogs\/python-inheritance\/\">Python Inheritance, Method Overloading &amp; Method Overriding<\/a><\/strong><\/p>\n<h4><strong>27. UnicodeDecodeError in Python<\/strong><\/h4>\n<p>The Unicode error during decoding is termed UnicodeDecodeError.<\/p>\n<h4><strong>28. UnicodeTranslateError in Python<\/strong><\/h4>\n<p>A UnicodeTranslateError occurs during translation.<\/p>\n<h4><strong>29. ValueError in Python<\/strong><\/h4>\n<p>You get a ValueError when you send in an argument of the correct type, but an improper value.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; int(input())<\/pre>\n<p>3.5<\/p>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#55&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>int(input())<\/p>\n<p>ValueError: invalid literal for int() with base 10: &#8216;3.5&#8217;<\/p>\n<h4><strong>30. ZeroDivisionError in Python<\/strong><\/h4>\n<p>Finally, a ZeroDivisionError is one we\u2019ve seen in section 3. When the denominator of a division is 0, this Python exception is raised. This doesn\u2019t necessarily violate syntax.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; print(1\/0)<\/pre>\n<p>Traceback (most recent call last):<\/p>\n<p>File &#8220;&lt;pyshell#56&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>print(1\/0)<\/p>\n<p>ZeroDivisionError: division by zero<\/p>\n<p>So, this is all about the Python Error and Python Exception. Hope you like our explanation.<\/p>\n<h3>6. Conclusion<\/h3>\n<p>In this module, we learned about Python errors and Python exceptions and looked at some built-in exceptions in Python. These are unexpected situations at runtime. Furthermore, if you have any queries, feel free to ask in the comment box.<\/p>\n<p><strong><a href=\"https:\/\/docs.python.org\/3\/tutorial\/errors.html\">Reference<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Python Error &#8211; Objective In this Python Error tutorial, we will discuss what a syntax error in Python is. Along with this, we will study Python exceptions, error messages, and come in-built exception&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":36054,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[4184,4185,10510,10511,10521],"class_list":["post-6264","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-errors-and-exceptions-in-python","tag-errors-in-python","tag-python-error-and-exceptions","tag-python-errors","tag-python-exceptions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is Python Exception - Python Error &amp; In-built Exception in Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Python Error and Python Exception- Learn about python errors, exceptions in pythons, possible in-built exceptions in python, Python Exception Message\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-exception\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Python Exception - Python Error &amp; In-built Exception in Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python Error and Python Exception- Learn about python errors, exceptions in pythons, possible in-built exceptions in python, Python Exception Message\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-exception\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-22T06:20:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-24T08:47:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Python Exception - Python Error &amp; In-built Exception in Python - DataFlair","description":"Python Error and Python Exception- Learn about python errors, exceptions in pythons, possible in-built exceptions in python, Python Exception Message","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-exception\/","og_locale":"en_US","og_type":"article","og_title":"What is Python Exception - Python Error &amp; In-built Exception in Python - DataFlair","og_description":"Python Error and Python Exception- Learn about python errors, exceptions in pythons, possible in-built exceptions in python, Python Exception Message","og_url":"https:\/\/data-flair.training\/blogs\/python-exception\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-01-22T06:20:13+00:00","article_modified_time":"2026-04-24T08:47:24+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-exception\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-exception\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"What is Python Exception &#8211; Python Error &amp; In-built Exception in Python","datePublished":"2018-01-22T06:20:13+00:00","dateModified":"2026-04-24T08:47:24+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-exception\/"},"wordCount":1372,"commentCount":2,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-exception\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions-1.jpg","keywords":["errors and exceptions in python","errors in python","python error and exceptions","python errors","python exceptions"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-exception\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-exception\/","url":"https:\/\/data-flair.training\/blogs\/python-exception\/","name":"What is Python Exception - Python Error &amp; In-built Exception in Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-exception\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-exception\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions-1.jpg","datePublished":"2018-01-22T06:20:13+00:00","dateModified":"2026-04-24T08:47:24+00:00","description":"Python Error and Python Exception- Learn about python errors, exceptions in pythons, possible in-built exceptions in python, Python Exception Message","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-exception\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-exception\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-exception\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Errors-and-Exceptions-1.jpg","width":1200,"height":628,"caption":"What is Python Error - Python Exception Message &amp; In-built Exception"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-exception\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"What is Python Exception &#8211; Python Error &amp; In-built Exception in Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=6264"}],"version-history":[{"count":8,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6264\/revisions"}],"predecessor-version":[{"id":147828,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6264\/revisions\/147828"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/36054"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=6264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=6264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=6264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}