<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python Errors on Python Beginner Help</title><link>https://pythonbeginner.help/errors/</link><description>Recent content in Python Errors on Python Beginner Help</description><generator>Hugo</generator><language>en-US</language><atom:link href="https://pythonbeginner.help/errors/index.xml" rel="self" type="application/rss+xml"/><item><title>AssertionError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/assertionerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/assertionerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="assertionerror-in-python-causes-and-fixes"&gt;AssertionError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;AssertionError&lt;/code&gt; happens when an &lt;code&gt;assert&lt;/code&gt; statement checks a condition and that condition is &lt;code&gt;False&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This error usually means your program reached a state that the code assumed should never happen. It is common in debugging, tests, and code that checks important assumptions.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;name must not be empty&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;AssertionError&lt;/code&gt; happens when an &lt;code&gt;assert&lt;/code&gt; condition is &lt;code&gt;False&lt;/code&gt;. To fix it:&lt;/p&gt;</description></item><item><title>AttributeError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/attributeerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/attributeerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="attributeerror-in-python-causes-and-fixes"&gt;AttributeError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;AttributeError&lt;/code&gt; happens when Python cannot find an attribute or method on an object.&lt;/p&gt;
&lt;p&gt;This usually means one of these is true:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You used a method on the wrong type of value&lt;/li&gt;
&lt;li&gt;You misspelled the attribute name&lt;/li&gt;
&lt;li&gt;Your variable is &lt;code&gt;None&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The variable changed to a different type earlier in the code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A common example is trying to use &lt;code&gt;.split()&lt;/code&gt; on a list instead of a string.&lt;/p&gt;</description></item><item><title>AttributeError: 'int' object has no attribute (Fix)</title><link>https://pythonbeginner.help/errors/attributeerror-int-object-has-no-attribute-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/attributeerror-int-object-has-no-attribute-fix/</guid><description>&lt;h1 id="attributeerror-int-object-has-no-attribute-fix"&gt;AttributeError: &lt;code&gt;'int'&lt;/code&gt; object has no attribute (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the error &lt;code&gt;AttributeError: 'int' object has no attribute&lt;/code&gt; by finding where a number is being used like a string, list, dictionary, or custom object.&lt;/p&gt;
&lt;p&gt;This usually means a variable contains an &lt;code&gt;int&lt;/code&gt;, but your code is trying to use a method or attribute that belongs to some other type.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Wrong: integers do not have string methods&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# print(value.lower())&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Fix 1: convert to string first&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Fix 2: check the type before calling an attribute&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This error happens when you call a method or access an attribute that integers do not have, such as &lt;code&gt;.lower()&lt;/code&gt;, &lt;code&gt;.append()&lt;/code&gt;, &lt;code&gt;.keys()&lt;/code&gt;, or a custom attribute name.&lt;/p&gt;</description></item><item><title>AttributeError: 'list' object has no attribute (Fix)</title><link>https://pythonbeginner.help/errors/attributeerror-list-object-has-no-attribute-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/attributeerror-list-object-has-no-attribute-fix/</guid><description>&lt;h1 id="attributeerror-list-object-has-no-attribute-fix"&gt;AttributeError: &lt;code&gt;'list' object has no attribute&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when Python sees a &lt;strong&gt;list&lt;/strong&gt;, but your code tries to use a method or attribute that &lt;strong&gt;lists do not have&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;A common example is using a &lt;strong&gt;string method&lt;/strong&gt; like &lt;code&gt;lower()&lt;/code&gt; on a list:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;my_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;A&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;B&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;C&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;my_list&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That fails because &lt;code&gt;lower()&lt;/code&gt; works on strings, not on lists.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;my_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;a&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;b&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;c&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Wrong: lists do not have string methods like lower()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# my_list.lower()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Fix 1: use a list method&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;my_list&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;d&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Fix 2: apply the string method to each item&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;lowered&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;my_list&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lowered&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;</description></item><item><title>AttributeError: 'NoneType' object has no attribute (Fix)</title><link>https://pythonbeginner.help/errors/attributeerror-nonetype-object-has-no-attribute-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/attributeerror-nonetype-object-has-no-attribute-fix/</guid><description>&lt;h1 id="attributeerror-nonetype-object-has-no-attribute-fix"&gt;AttributeError: &lt;code&gt;'NoneType' object has no attribute&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when you try to use an attribute or method on &lt;code&gt;None&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In Python, &lt;code&gt;None&lt;/code&gt; means “no value”. So if a variable is &lt;code&gt;None&lt;/code&gt;, you cannot call methods like &lt;code&gt;.strip()&lt;/code&gt;, &lt;code&gt;.append()&lt;/code&gt;, &lt;code&gt;.get()&lt;/code&gt;, or access attributes on it.&lt;/p&gt;
&lt;p&gt;The fix is usually simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;find where &lt;code&gt;None&lt;/code&gt; came from&lt;/li&gt;
&lt;li&gt;make sure you have the right object before using it&lt;/li&gt;
&lt;li&gt;add a check or default value if &lt;code&gt;None&lt;/code&gt; is possible&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_name&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;No name returned&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This error happens when you try to use a method or attribute on &lt;code&gt;None&lt;/code&gt;. Check the variable before calling methods like &lt;code&gt;.strip()&lt;/code&gt;, &lt;code&gt;.append()&lt;/code&gt;, or &lt;code&gt;.get()&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>AttributeError: 'str' object has no attribute (Fix)</title><link>https://pythonbeginner.help/errors/attributeerror-str-object-has-no-attribute-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/attributeerror-str-object-has-no-attribute-fix/</guid><description>&lt;h1 id="attributeerror-str-object-has-no-attribute-fix"&gt;AttributeError: &lt;code&gt;'str' object has no attribute&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when your variable is a string, but your code uses a method or attribute that does not belong to Python strings.&lt;/p&gt;
&lt;p&gt;In simple terms, Python is telling you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;“This value is text”&lt;/li&gt;
&lt;li&gt;“The thing after the dot does not exist on text”&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This often happens when you expected a list, dictionary, or custom object, but the variable is actually a string.&lt;/p&gt;</description></item><item><title>AttributeError: module has no attribute (Fix)</title><link>https://pythonbeginner.help/errors/attributeerror-module-has-no-attribute-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/attributeerror-module-has-no-attribute-fix/</guid><description>&lt;h1 id="attributeerror-module-has-no-attribute-fix"&gt;AttributeError: module has no attribute (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the error &lt;strong&gt;&lt;code&gt;AttributeError: module has no attribute&lt;/code&gt;&lt;/strong&gt; by checking what module Python imported, whether the attribute name is correct, and whether your own file name is hiding the real module.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;math&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Check what names the module actually has&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If the attribute is missing, check:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the spelling&lt;/li&gt;
&lt;li&gt;your &lt;code&gt;import&lt;/code&gt; statement&lt;/li&gt;
&lt;li&gt;whether you named your own file the same as the module&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="what-this-error-means"&gt;What this error means &lt;a class="heading-anchor" href="#what-this-error-means" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This error means:&lt;/p&gt;</description></item><item><title>AttributeError: object has no attribute (Fix)</title><link>https://pythonbeginner.help/errors/attributeerror-object-has-no-attribute-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/attributeerror-object-has-no-attribute-fix/</guid><description>&lt;h1 id="attributeerror-object-has-no-attribute-fix"&gt;AttributeError: object has no attribute (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when Python finds the object before the dot, but cannot find the attribute or method after the dot.&lt;/p&gt;
&lt;p&gt;In simple terms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The variable exists&lt;/li&gt;
&lt;li&gt;But that kind of object does not have the thing you tried to use&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, a list has &lt;code&gt;append()&lt;/code&gt;, but an integer does not. A string has &lt;code&gt;upper()&lt;/code&gt;, but a list does not.&lt;/p&gt;
&lt;p&gt;If you are not sure what value you actually have, start by checking its type with &lt;a href="https://pythonbeginner.help/reference/python-type-function-explained/"&gt;&lt;code&gt;type()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Common Python Errors Explained (Beginner Guide)</title><link>https://pythonbeginner.help/errors/common-python-errors-explained-beginner-guide/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/common-python-errors-explained-beginner-guide/</guid><description>&lt;h1 id="common-python-errors-explained-beginner-guide"&gt;Common Python Errors Explained (Beginner Guide)&lt;/h1&gt;
&lt;p&gt;Python error messages can look confusing at first. This page gives you a simple map of the errors beginners see most often.&lt;/p&gt;
&lt;p&gt;You will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what common error types usually mean&lt;/li&gt;
&lt;li&gt;how to read a traceback&lt;/li&gt;
&lt;li&gt;how to tell syntax, type, value, name, index, and file errors apart&lt;/li&gt;
&lt;li&gt;which specific error page to open next&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is an overview page. It is meant to help you identify the error category quickly, not replace detailed fix guides for each exact error.&lt;/p&gt;</description></item><item><title>FileNotFoundError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/filenotfounderror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/filenotfounderror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="filenotfounderror-in-python-causes-and-fixes"&gt;FileNotFoundError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;FileNotFoundError&lt;/code&gt; means Python could not find the file or folder you asked it to use.&lt;/p&gt;
&lt;p&gt;This error often appears when you use &lt;code&gt;open()&lt;/code&gt;, &lt;code&gt;os.rename()&lt;/code&gt;, &lt;code&gt;os.remove()&lt;/code&gt;, or other file operations. In most cases, the problem is not Python itself. The problem is the path.&lt;/p&gt;
&lt;p&gt;A very common beginner mistake is thinking Python looks for files in the same folder as the script. Sometimes it does, but often Python uses the &lt;strong&gt;current working directory&lt;/strong&gt; instead.&lt;/p&gt;</description></item><item><title>FileNotFoundError vs PermissionError Explained</title><link>https://pythonbeginner.help/errors/filenotfounderror-vs-permissionerror-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/filenotfounderror-vs-permissionerror-explained/</guid><description>&lt;h1 id="filenotfounderror-vs-permissionerror-explained"&gt;FileNotFoundError vs PermissionError Explained&lt;/h1&gt;
&lt;p&gt;These two Python errors look similar because both happen when you work with files or folders.&lt;/p&gt;
&lt;p&gt;But they mean different things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;FileNotFoundError&lt;/code&gt;&lt;/strong&gt; means Python cannot find the path you gave.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;PermissionError&lt;/code&gt;&lt;/strong&gt; means Python found the path, but it is not allowed to access it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page helps you tell them apart quickly, understand why each one happens, and choose the right fix.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use this pattern to separate a missing file problem from a permission problem:&lt;/p&gt;</description></item><item><title>FileNotFoundError: [Errno 2] No such file or directory (Fix)</title><link>https://pythonbeginner.help/errors/filenotfounderror-errno-2-no-such-file-or-directory-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/filenotfounderror-errno-2-no-such-file-or-directory-fix/</guid><description>&lt;h1 id="filenotfounderror-errno-2-no-such-file-or-directory-fix"&gt;FileNotFoundError: [Errno 2] No such file or directory (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;FileNotFoundError: [Errno 2] No such file or directory&lt;/code&gt; means Python could not find the file or folder path you gave it.&lt;/p&gt;
&lt;p&gt;This error is very common when working with &lt;code&gt;open()&lt;/code&gt;, &lt;code&gt;os&lt;/code&gt;, or &lt;code&gt;pathlib&lt;/code&gt;. In most cases, the problem is one of these:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The file name is wrong&lt;/li&gt;
&lt;li&gt;The file is in a different folder&lt;/li&gt;
&lt;li&gt;The path is relative, but Python is running from a different working directory&lt;/li&gt;
&lt;li&gt;A folder in the path does not exist&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want a fast way to check the path before opening the file, use this:&lt;/p&gt;</description></item><item><title>ImportError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/importerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/importerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="importerror-in-python-causes-and-fixes"&gt;ImportError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;ImportError&lt;/code&gt; means Python could not complete an &lt;code&gt;import&lt;/code&gt; statement.&lt;/p&gt;
&lt;p&gt;This usually happens because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the module is missing&lt;/li&gt;
&lt;li&gt;the name you are trying to import does not exist&lt;/li&gt;
&lt;li&gt;Python is using the wrong environment&lt;/li&gt;
&lt;li&gt;your project files are named or arranged in a way that breaks imports&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Beginners often mix up &lt;code&gt;ImportError&lt;/code&gt; and &lt;code&gt;ModuleNotFoundError&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ModuleNotFoundError&lt;/code&gt; is more specific&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ImportError&lt;/code&gt; is broader&lt;/li&gt;
&lt;li&gt;Python may find the module, but still fail to import something from it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page helps you check the most common causes step by step.&lt;/p&gt;</description></item><item><title>ImportError: cannot import name (Fix)</title><link>https://pythonbeginner.help/errors/importerror-cannot-import-name-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/importerror-cannot-import-name-fix/</guid><description>&lt;h1 id="importerror-cannot-import-name-fix"&gt;ImportError: cannot import name (Fix)&lt;/h1&gt;
&lt;p&gt;If you see the Python error &lt;strong&gt;&lt;code&gt;ImportError: cannot import name ...&lt;/code&gt;&lt;/strong&gt;, Python was able to find the module, but it could not find the specific function, class, or variable you asked for.&lt;/p&gt;
&lt;p&gt;This usually happens because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the name is spelled wrong&lt;/li&gt;
&lt;li&gt;you imported from the wrong module&lt;/li&gt;
&lt;li&gt;the name is not available at the top level&lt;/li&gt;
&lt;li&gt;there is a circular import&lt;/li&gt;
&lt;li&gt;a local file is conflicting with a real module&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This guide shows how to find the cause and fix it.&lt;/p&gt;</description></item><item><title>ImportError: No module named X (Fix)</title><link>https://pythonbeginner.help/errors/importerror-no-module-named-x-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/importerror-no-module-named-x-fix/</guid><description>&lt;h1 id="importerror-no-module-named-x-fix"&gt;ImportError: No module named X (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when Python tries to import a module but cannot find it.&lt;/p&gt;
&lt;p&gt;In many cases, the fix is simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The package is not installed&lt;/li&gt;
&lt;li&gt;It was installed in the wrong Python environment&lt;/li&gt;
&lt;li&gt;The import name is wrong&lt;/li&gt;
&lt;li&gt;Your own file name is blocking the real module&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Start with the fastest checks first. That usually solves the problem quickly.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;python -m pip install package_name
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use the same Python interpreter that runs your script. Replace &lt;code&gt;package_name&lt;/code&gt; with the real package name.&lt;/p&gt;</description></item><item><title>IndentationError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/indentationerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/indentationerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="indentationerror-in-python-causes-and-fixes"&gt;IndentationError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;Fix &lt;code&gt;IndentationError&lt;/code&gt; by understanding what the error means, why Python requires indentation, and how to correct common spacing mistakes in your code.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Correct indentation&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;After a line that ends with a colon (&lt;code&gt;:&lt;/code&gt;), indent the next block consistently. Use the same indentation style throughout the file.&lt;/p&gt;
&lt;h2 id="what-this-error-means"&gt;What this error means &lt;a class="heading-anchor" href="#what-this-error-means" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python uses indentation to define code blocks.&lt;/p&gt;</description></item><item><title>IndentationError: expected an indented block (Fix)</title><link>https://pythonbeginner.help/errors/indentationerror-expected-an-indented-block-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/indentationerror-expected-an-indented-block-fix/</guid><description>&lt;h1 id="indentationerror-expected-an-indented-block-fix"&gt;IndentationError: expected an indented block (Fix)&lt;/h1&gt;
&lt;p&gt;Python shows &lt;code&gt;IndentationError: expected an indented block&lt;/code&gt; when it reaches a line that should contain a code block, but the next line is not indented.&lt;/p&gt;
&lt;p&gt;This usually happens after lines like &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;def&lt;/code&gt;, &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;try&lt;/code&gt;, or &lt;code&gt;else&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;This line is indented correctly&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Python expects an indented block after lines like &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;def&lt;/code&gt;, &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;try&lt;/code&gt;, and &lt;code&gt;else&lt;/code&gt;. Add indentation, usually 4 spaces.&lt;/p&gt;</description></item><item><title>IndentationError: unexpected indent (Fix)</title><link>https://pythonbeginner.help/errors/indentationerror-unexpected-indent-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/indentationerror-unexpected-indent-fix/</guid><description>&lt;h1 id="indentationerror-unexpected-indent-fix"&gt;IndentationError: unexpected indent (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;IndentationError: unexpected indent&lt;/code&gt; means Python found spaces or tabs at the start of a line where it was &lt;strong&gt;not expecting a new block&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This usually happens when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a top-level line starts with extra spaces&lt;/li&gt;
&lt;li&gt;a line is indented even though the line above it did not start a block&lt;/li&gt;
&lt;li&gt;copied code contains hidden tabs or spaces&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The good news is that this error is usually fast to fix. Python often points to the exact line that caused the problem.&lt;/p&gt;</description></item><item><title>IndentationError: unindent does not match any outer indentation level (Fix)</title><link>https://pythonbeginner.help/errors/indentationerror-unindent-does-not-match-any-outer-indentation-level-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/indentationerror-unindent-does-not-match-any-outer-indentation-level-fix/</guid><description>&lt;h1 id="indentationerror-unindent-does-not-match-any-outer-indentation-level-fix"&gt;IndentationError: unindent does not match any outer indentation level (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;code&gt;IndentationError: unindent does not match any outer indentation level&lt;/code&gt;. This error usually means one line is indented differently from the surrounding block. On this page, you will learn what the error means, why it happens, how to find the bad indentation, and how to fix it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use one indentation style consistently. For most beginners, the safest choice is &lt;strong&gt;4 spaces per indentation level&lt;/strong&gt;. Do not mix tabs and spaces.&lt;/p&gt;</description></item><item><title>IndexError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/indexerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/indexerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="indexerror-in-python-causes-and-fixes"&gt;IndexError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;IndexError&lt;/code&gt; means your code tried to use a position that does not exist in a sequence.&lt;/p&gt;
&lt;p&gt;This usually happens with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;lists&lt;/li&gt;
&lt;li&gt;tuples&lt;/li&gt;
&lt;li&gt;strings&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In Python, indexing starts at &lt;code&gt;0&lt;/code&gt;, not &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So if a list has 3 items, the valid indexes are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;2&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you try to access index &lt;code&gt;3&lt;/code&gt;, Python raises an &lt;code&gt;IndexError&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If you are not sure whether an index exists, check it before using it:&lt;/p&gt;</description></item><item><title>IndexError: list index out of range (Fix Explained)</title><link>https://pythonbeginner.help/errors/indexerror-list-index-out-of-range-fix-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/indexerror-list-index-out-of-range-fix-explained/</guid><description>&lt;h1 id="indexerror-list-index-out-of-range-fix-explained"&gt;IndexError: list index out of range (Fix Explained)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;IndexError: list index out of range&lt;/code&gt; means your code is trying to read a list position that does not exist.&lt;/p&gt;
&lt;p&gt;This usually happens when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the index is too large&lt;/li&gt;
&lt;li&gt;the list is empty&lt;/li&gt;
&lt;li&gt;a loop goes one step too far&lt;/li&gt;
&lt;li&gt;you expect more items than are really in the list&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The good news is that this error is usually easy to fix. In most cases, you need to check the list length with &lt;a href="https://pythonbeginner.help/reference/python-list-length-len/"&gt;&lt;code&gt;len()&lt;/code&gt;&lt;/a&gt; or use a safer looping pattern.&lt;/p&gt;</description></item><item><title>IndexError: tuple index out of range (Fix)</title><link>https://pythonbeginner.help/errors/indexerror-tuple-index-out-of-range-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/indexerror-tuple-index-out-of-range-fix/</guid><description>&lt;h1 id="indexerror-tuple-index-out-of-range-fix"&gt;IndexError: tuple index out of range (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;IndexError: tuple index out of range&lt;/code&gt; means your code is trying to read a tuple position that does not exist.&lt;/p&gt;
&lt;p&gt;This usually happens when you use an index that is too large, or when you forget that Python indexes start at &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;red&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;green&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;blue&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Wrong: colors[3] # IndexError&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Correct: use a valid index&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Or check length first&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Index out of range&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Tuple indexes start at &lt;code&gt;0&lt;/code&gt;. A tuple with 3 items has valid indexes &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;1&lt;/code&gt;, and &lt;code&gt;2&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>IsADirectoryError: [Errno 21] Is a directory (Fix)</title><link>https://pythonbeginner.help/errors/isadirectoryerror-errno-21-is-a-directory-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/isadirectoryerror-errno-21-is-a-directory-fix/</guid><description>&lt;h1 id="isadirectoryerror-errno-21-is-a-directory-fix"&gt;IsADirectoryError: [Errno 21] Is a directory (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;IsADirectoryError: [Errno 21] Is a directory&lt;/code&gt; happens when your Python code tries to open, read, write, or otherwise use a &lt;strong&gt;folder path&lt;/strong&gt; where Python expects a &lt;strong&gt;file path&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This is a common beginner error when working with &lt;code&gt;open()&lt;/code&gt;, file paths, or folder loops. The fix is usually simple: check the path, confirm whether it points to a file or a directory, and use the right operation for that path.&lt;/p&gt;</description></item><item><title>KeyboardInterrupt Exception in Python Explained</title><link>https://pythonbeginner.help/errors/keyboardinterrupt-exception-in-python-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/keyboardinterrupt-exception-in-python-explained/</guid><description>&lt;h1 id="keyboardinterrupt-exception-in-python-explained"&gt;KeyboardInterrupt Exception in Python Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;KeyboardInterrupt&lt;/code&gt; is a Python exception that happens when &lt;strong&gt;you stop a running program from the keyboard&lt;/strong&gt;. In most cases, this means you pressed &lt;strong&gt;Ctrl+C&lt;/strong&gt; in the terminal.&lt;/p&gt;
&lt;p&gt;This page explains what &lt;code&gt;KeyboardInterrupt&lt;/code&gt; means, when it appears, and how to handle it safely. It is usually &lt;strong&gt;not a bug in your code&lt;/strong&gt;. Instead, it means the program was interrupted by the user.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If you want your program to stop cleanly when the user presses Ctrl+C, wrap the code in a &lt;code&gt;try-except&lt;/code&gt; block:&lt;/p&gt;</description></item><item><title>KeyError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/keyerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/keyerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="keyerror-in-python-causes-and-fixes"&gt;KeyError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;A &lt;code&gt;KeyError&lt;/code&gt; in Python usually happens when you try to read a dictionary value using a key that does not exist.&lt;/p&gt;
&lt;p&gt;This error is very common when working with dictionaries, JSON data, and API responses. The good news is that it is usually easy to fix once you know why it happens.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;name&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Ana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Safe access&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# None&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Check before access&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Key not found&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;a href="https://pythonbeginner.help/reference/python-dictionary-get-method"&gt;&lt;code&gt;dict.get()&lt;/code&gt;&lt;/a&gt; when a key may be missing, or check with &lt;code&gt;in&lt;/code&gt; before using square brackets.&lt;/p&gt;</description></item><item><title>KeyError vs IndexError in Python Explained</title><link>https://pythonbeginner.help/errors/keyerror-vs-indexerror-in-python-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/keyerror-vs-indexerror-in-python-explained/</guid><description>&lt;h1 id="keyerror-vs-indexerror-in-python-explained"&gt;KeyError vs IndexError in Python Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;KeyError&lt;/code&gt; and &lt;code&gt;IndexError&lt;/code&gt; both happen when your code tries to access something that is not available.&lt;/p&gt;
&lt;p&gt;The difference is simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;KeyError&lt;/code&gt; is about a &lt;strong&gt;missing dictionary key&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;IndexError&lt;/code&gt; is about a &lt;strong&gt;list or tuple position that does not exist&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you can quickly tell whether you are working with a dictionary or a sequence like a list, you can usually fix the problem fast.&lt;/p&gt;</description></item><item><title>KeyError when accessing dictionary values (Fix)</title><link>https://pythonbeginner.help/errors/keyerror-when-accessing-dictionary-values-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/keyerror-when-accessing-dictionary-values-fix/</guid><description>&lt;h1 id="keyerror-when-accessing-dictionary-values-fix"&gt;KeyError when accessing dictionary values (Fix)&lt;/h1&gt;
&lt;p&gt;A &lt;code&gt;KeyError&lt;/code&gt; happens when you try to access a dictionary value using a key that does not exist.&lt;/p&gt;
&lt;p&gt;This usually happens with square bracket access like &lt;code&gt;data[&amp;quot;age&amp;quot;]&lt;/code&gt;. If the key is missing, Python stops and raises an error.&lt;/p&gt;
&lt;p&gt;This page shows what the error means, why it happens, and how to fix it safely.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;name&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Ana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Safe access&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# None&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Or check first&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Key not found&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;dict.get()&lt;/code&gt; when a key might be missing, or check with &lt;code&gt;in&lt;/code&gt; before using square brackets.&lt;/p&gt;</description></item><item><title>KeyError: key not found in dictionary (Fix)</title><link>https://pythonbeginner.help/errors/keyerror-key-not-found-in-dictionary-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/keyerror-key-not-found-in-dictionary-fix/</guid><description>&lt;h1 id="keyerror-key-not-found-in-dictionary-fix"&gt;KeyError: key not found in dictionary (Fix)&lt;/h1&gt;
&lt;p&gt;A &lt;code&gt;KeyError&lt;/code&gt; happens when you try to read a dictionary key that is not there.&lt;/p&gt;
&lt;p&gt;This usually happens when you use square brackets, like &lt;code&gt;data[&amp;quot;age&amp;quot;]&lt;/code&gt;, but the dictionary does not contain &lt;code&gt;&amp;quot;age&amp;quot;&lt;/code&gt;. Python raises an error because dictionary keys must match exactly.&lt;/p&gt;
&lt;p&gt;This guide shows what the error means, why it happens, and simple ways to fix it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;name&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Sam&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Safe access&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# None&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Or check first&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Key not found&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;dict.get()&lt;/code&gt; when a key might be missing, or check with &lt;code&gt;in&lt;/code&gt; before using square brackets.&lt;/p&gt;</description></item><item><title>KeyError: popitem(): dictionary is empty (Fix)</title><link>https://pythonbeginner.help/errors/keyerror-popitem-dictionary-is-empty-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/keyerror-popitem-dictionary-is-empty-fix/</guid><description>&lt;h1 id="keyerror-popitem-dictionary-is-empty-fix"&gt;KeyError: popitem(): dictionary is empty (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;code&gt;&amp;quot;KeyError: popitem(): dictionary is empty&amp;quot;&lt;/code&gt;. This error happens when you call &lt;code&gt;popitem()&lt;/code&gt; on a dictionary that has no items left.&lt;/p&gt;
&lt;p&gt;This page explains what the error means, shows a small example that causes it, and gives simple ways to avoid it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Check that the dictionary is not empty before calling &lt;code&gt;popitem()&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;popitem&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Dictionary is empty&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;An empty dictionary is &lt;code&gt;False&lt;/code&gt;, so &lt;code&gt;if data:&lt;/code&gt; is a simple way to avoid this error.&lt;/p&gt;</description></item><item><title>MemoryError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/memoryerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/memoryerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="memoryerror-in-python-causes-and-fixes"&gt;MemoryError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;MemoryError&lt;/code&gt; means Python tried to create or grow an object, but there was not enough memory available.&lt;/p&gt;
&lt;p&gt;This usually happens when a program creates very large lists, strings, dictionaries, or reads too much data into memory at once. The fix is often not just “use more RAM.” In many cases, the better solution is to change how the program handles data.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A common fix is to avoid creating very large lists when you only need to loop through values.&lt;/p&gt;</description></item><item><title>ModuleNotFoundError: No module named X (Fix)</title><link>https://pythonbeginner.help/errors/modulenotfounderror-no-module-named-x-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/modulenotfounderror-no-module-named-x-fix/</guid><description>&lt;h1 id="modulenotfounderror-no-module-named-x-fix"&gt;ModuleNotFoundError: No module named X (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;ModuleNotFoundError: No module named 'X'&lt;/code&gt; means Python tried to import a module but could not find it.&lt;/p&gt;
&lt;p&gt;This usually happens because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the package is not installed&lt;/li&gt;
&lt;li&gt;it is installed in the wrong Python environment&lt;/li&gt;
&lt;li&gt;the import name is wrong&lt;/li&gt;
&lt;li&gt;a local file is hiding the real package&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This guide helps you find the cause quickly and fix it step by step.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;python -m pip install requests
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Replace &lt;code&gt;requests&lt;/code&gt; with the missing module name.&lt;/p&gt;</description></item><item><title>NameError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/nameerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/nameerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="nameerror-in-python-causes-and-fixes"&gt;NameError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;A &lt;code&gt;NameError&lt;/code&gt; in Python means you used a name that Python cannot find.&lt;/p&gt;
&lt;p&gt;That name might be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A variable&lt;/li&gt;
&lt;li&gt;A function&lt;/li&gt;
&lt;li&gt;A class&lt;/li&gt;
&lt;li&gt;An imported module&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This error is common for beginners because Python only knows names that were already created, assigned, or imported. If the name does not exist in the current scope, Python raises &lt;code&gt;NameError&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A &lt;code&gt;NameError&lt;/code&gt; happens when Python sees a variable, function, or module name that does not exist in the current scope.&lt;/p&gt;</description></item><item><title>NameError: global name not defined (Fix)</title><link>https://pythonbeginner.help/errors/nameerror-global-name-not-defined-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/nameerror-global-name-not-defined-fix/</guid><description>&lt;h1 id="nameerror-global-name-not-defined-fix"&gt;NameError: global name not defined (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;strong&gt;&amp;ldquo;NameError: global name not defined&amp;rdquo;&lt;/strong&gt; by finding the missing or misspelled name and making sure it exists before you use it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A &lt;code&gt;NameError&lt;/code&gt; happens when Python cannot find a variable, function, or module name. Define it first, spell it correctly, and use the right scope.&lt;/p&gt;
&lt;h2 id="what-this-error-means"&gt;What this error means &lt;a class="heading-anchor" href="#what-this-error-means" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python raises this error when it tries to use a name that does not exist in the current scope.&lt;/p&gt;</description></item><item><title>NameError: name is not defined (Fix)</title><link>https://pythonbeginner.help/errors/nameerror-name-is-not-defined-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/nameerror-name-is-not-defined-fix/</guid><description>&lt;h1 id="nameerror-name-is-not-defined-fix"&gt;NameError: name is not defined (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;code&gt;NameError: name is not defined&lt;/code&gt;. This page explains what the error means, why it happens, and the most common ways to correct it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;user_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Sam&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This error happens when Python sees a name that has not been created yet, is misspelled, or is outside the current scope.&lt;/p&gt;
&lt;h2 id="what-this-error-means"&gt;What this error means &lt;a class="heading-anchor" href="#what-this-error-means" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;NameError&lt;/code&gt; means Python found a variable, function, or module name it does not know.&lt;/p&gt;</description></item><item><title>NotADirectoryError: [Errno 20] Not a directory (Fix)</title><link>https://pythonbeginner.help/errors/notadirectoryerror-errno-20-not-a-directory-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/notadirectoryerror-errno-20-not-a-directory-fix/</guid><description>&lt;h1 id="notadirectoryerror-errno-20-not-a-directory-fix"&gt;NotADirectoryError: [Errno 20] Not a directory (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;NotADirectoryError: [Errno 20] Not a directory&lt;/code&gt; happens when Python expects a &lt;strong&gt;folder path&lt;/strong&gt;, but your code gives it a &lt;strong&gt;file path&lt;/strong&gt; instead.&lt;/p&gt;
&lt;p&gt;This usually appears with functions like &lt;code&gt;os.listdir()&lt;/code&gt;, &lt;code&gt;os.chdir()&lt;/code&gt;, and &lt;code&gt;os.scandir()&lt;/code&gt;. These functions work with directories, not files.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use &lt;code&gt;os.path.isdir()&lt;/code&gt; before calling a function that expects a directory:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;notes.txt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;listdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;This path is not a directory:&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;What this does:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>OSError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/oserror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/oserror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="oserror-in-python-causes-and-fixes"&gt;OSError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;OSError&lt;/code&gt; is a general Python error for operating system related problems.&lt;/p&gt;
&lt;p&gt;You will often see it when your code works with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;files&lt;/li&gt;
&lt;li&gt;folders&lt;/li&gt;
&lt;li&gt;paths&lt;/li&gt;
&lt;li&gt;permissions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For beginners, the most important thing to know is this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;OSError&lt;/code&gt; usually means something is wrong with the path, file, folder, or access&lt;/li&gt;
&lt;li&gt;the error message after &lt;code&gt;OSError&lt;/code&gt; usually tells you what the real problem is&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A quick way to start debugging is to check whether the path actually exists before using it.&lt;/p&gt;</description></item><item><title>OverflowError: numerical result out of range (Fix)</title><link>https://pythonbeginner.help/errors/overflowerror-numerical-result-out-of-range-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/overflowerror-numerical-result-out-of-range-fix/</guid><description>&lt;h1 id="overflowerror-numerical-result-out-of-range-fix"&gt;OverflowError: numerical result out of range (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;OverflowError: numerical result out of range&lt;/code&gt; means a calculation produced a number that is too large for Python to handle in that specific operation.&lt;/p&gt;
&lt;p&gt;This error is common with floating-point math and functions from the &lt;code&gt;math&lt;/code&gt; module. It is less common with normal Python integers.&lt;/p&gt;
&lt;p&gt;If you are trying to fix it quickly, start by checking whether your input has become extremely large before the failing calculation.&lt;/p&gt;</description></item><item><title>PermissionError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/permissionerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/permissionerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="permissionerror-in-python-causes-and-fixes"&gt;PermissionError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;PermissionError&lt;/code&gt; means Python tried to access a file or folder, but your user account was not allowed to do it.&lt;/p&gt;
&lt;p&gt;This usually happens when you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;open a protected file&lt;/li&gt;
&lt;li&gt;write to a restricted folder&lt;/li&gt;
&lt;li&gt;try to rename or delete something you do not control&lt;/li&gt;
&lt;li&gt;pass a folder path to &lt;code&gt;open()&lt;/code&gt; by mistake&lt;/li&gt;
&lt;li&gt;use a file that another program is already using&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A common message looks like this:&lt;/p&gt;</description></item><item><title>PermissionError: [Errno 13] Permission denied (Fix)</title><link>https://pythonbeginner.help/errors/permissionerror-errno-13-permission-denied-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/permissionerror-errno-13-permission-denied-fix/</guid><description>&lt;h1 id="permissionerror-errno-13-permission-denied-fix"&gt;PermissionError: [Errno 13] Permission denied (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;PermissionError: [Errno 13] Permission denied&lt;/code&gt; means Python asked the operating system to access a file, folder, or other resource, but the operating system refused.&lt;/p&gt;
&lt;p&gt;This usually happens when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;your program does not have permission to read or write something&lt;/li&gt;
&lt;li&gt;the path points to a folder instead of a file&lt;/li&gt;
&lt;li&gt;you are trying to save in a protected location&lt;/li&gt;
&lt;li&gt;another program is locking the file&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The good news is that this error is often easy to fix once you check the path, file type, and location.&lt;/p&gt;</description></item><item><title>RecursionError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/recursionerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/recursionerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="recursionerror-in-python-causes-and-fixes"&gt;RecursionError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;RecursionError&lt;/code&gt; happens when a function keeps calling itself too many times.&lt;/p&gt;
&lt;p&gt;In Python, recursion means a function calls itself to solve a smaller version of the same problem. This can be useful, but the function must have a clear way to stop. If it never stops, or if it goes too deep, Python raises &lt;code&gt;RecursionError&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;countdown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;# base case&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;countdown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;countdown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>RecursionError: maximum recursion depth exceeded (Fix)</title><link>https://pythonbeginner.help/errors/recursionerror-maximum-recursion-depth-exceeded-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/recursionerror-maximum-recursion-depth-exceeded-fix/</guid><description>&lt;h1 id="recursionerror-maximum-recursion-depth-exceeded-fix"&gt;RecursionError: maximum recursion depth exceeded (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;RecursionError: maximum recursion depth exceeded&lt;/code&gt; means Python stopped your program because a function called itself too many times.&lt;/p&gt;
&lt;p&gt;This usually happens with recursive functions. A recursive function is a function that calls itself. Python allows recursion, but it also has a safety limit so your program does not keep running forever and using too much memory.&lt;/p&gt;
&lt;p&gt;If you want the quick fix first: check that your function has a base case, and make sure every recursive call moves toward that stopping point.&lt;/p&gt;</description></item><item><title>RuntimeError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/runtimeerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/runtimeerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="runtimeerror-in-python-causes-and-fixes"&gt;RuntimeError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;RuntimeError&lt;/code&gt; is a general Python exception that happens &lt;strong&gt;while your program is running&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For beginners, this error can feel vague because the name does not tell you exactly what went wrong. The important clue is usually the &lt;strong&gt;message after &lt;code&gt;RuntimeError&lt;/code&gt;&lt;/strong&gt; and the &lt;strong&gt;traceback line that points to the problem&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This guide explains what &lt;code&gt;RuntimeError&lt;/code&gt; means, why it happens, and how to debug it using simple real examples.&lt;/p&gt;</description></item><item><title>StopIteration Exception in Python Explained</title><link>https://pythonbeginner.help/errors/stopiteration-exception-in-python-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/stopiteration-exception-in-python-explained/</guid><description>&lt;h1 id="stopiteration-exception-in-python-explained"&gt;StopIteration Exception in Python Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;StopIteration&lt;/code&gt; happens when an &lt;strong&gt;iterator&lt;/strong&gt; has no more values to return.&lt;/p&gt;
&lt;p&gt;This does &lt;strong&gt;not always mean something is broken&lt;/strong&gt;. In Python, &lt;code&gt;StopIteration&lt;/code&gt; is a normal signal used to say, “there are no more items.”&lt;/p&gt;
&lt;p&gt;Beginners usually see it when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;calling &lt;code&gt;next()&lt;/code&gt; too many times&lt;/li&gt;
&lt;li&gt;using a &lt;code&gt;while True&lt;/code&gt; loop with an iterator&lt;/li&gt;
&lt;li&gt;reusing an iterator that is already finished&lt;/li&gt;
&lt;li&gt;raising &lt;code&gt;StopIteration&lt;/code&gt; manually inside a generator&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you use a &lt;code&gt;for&lt;/code&gt; loop, Python usually handles this for you automatically. The exception becomes visible when you call &lt;code&gt;next()&lt;/code&gt; yourself and do not handle the end of the iterator.&lt;/p&gt;</description></item><item><title>SyntaxError: EOL while scanning string literal (Fix)</title><link>https://pythonbeginner.help/errors/syntaxerror-eol-while-scanning-string-literal-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/syntaxerror-eol-while-scanning-string-literal-fix/</guid><description>&lt;h1 id="syntaxerror-eol-while-scanning-string-literal-fix"&gt;SyntaxError: EOL while scanning string literal (Fix)&lt;/h1&gt;
&lt;p&gt;This error means Python found the start of a string, but never found the end of it.&lt;/p&gt;
&lt;p&gt;In simple terms, you opened a string with a quote, but the closing quote is missing or incorrect. Because this is a syntax error, your code will not run until you fix it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Alice&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Hello world&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This error usually happens when a string starts with a quote but does not end with the matching quote on the same line.&lt;/p&gt;</description></item><item><title>SyntaxError: indentation error (Fix)</title><link>https://pythonbeginner.help/errors/syntaxerror-indentation-error-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/syntaxerror-indentation-error-fix/</guid><description>&lt;h1 id="syntaxerror-indentation-error-fix"&gt;SyntaxError: indentation error (Fix)&lt;/h1&gt;
&lt;p&gt;This page helps beginners fix Python indentation-related syntax errors. It explains what the error means, why it happens, how to find the problem line, and how to correct it safely.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Correctly indented&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Python uses indentation to define code blocks. After a line ending with a colon, indent the next line consistently.&lt;/p&gt;
&lt;h2 id="what-this-error-means"&gt;What this error means &lt;a class="heading-anchor" href="#what-this-error-means" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python uses indentation to show which lines belong inside a block of code.&lt;/p&gt;</description></item><item><title>SyntaxError: invalid character in identifier (Fix)</title><link>https://pythonbeginner.help/errors/syntaxerror-invalid-character-in-identifier-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/syntaxerror-invalid-character-in-identifier-fix/</guid><description>&lt;h1 id="syntaxerror-invalid-character-in-identifier-fix"&gt;SyntaxError: invalid character in identifier (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;SyntaxError: invalid character in identifier&lt;/code&gt; means Python found a character in your code that does not belong there.&lt;/p&gt;
&lt;p&gt;This usually happens when code contains a character that looks normal but is not the normal Python version. Common examples include curly quotes, an em dash, or a hidden Unicode symbol copied from a website, PDF, or document.&lt;/p&gt;
&lt;p&gt;This page shows what the error means, what causes it, how to find the bad character, and how to fix it.&lt;/p&gt;</description></item><item><title>SyntaxError: invalid syntax (Fix)</title><link>https://pythonbeginner.help/errors/syntaxerror-invalid-syntax-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/syntaxerror-invalid-syntax-fix/</guid><description>&lt;h1 id="syntaxerror-invalid-syntax-fix"&gt;SyntaxError: invalid syntax (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;SyntaxError: invalid syntax&lt;/code&gt; means Python could not understand part of your code.&lt;/p&gt;
&lt;p&gt;This is one of the most common beginner errors. It usually happens because something is missing, extra, or written in the wrong form.&lt;/p&gt;
&lt;p&gt;The tricky part is this: Python often points to the place where it &lt;em&gt;noticed&lt;/em&gt; the problem, not the place where the mistake actually started. That is why you should always check the highlighted line &lt;strong&gt;and the line just before it&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>SyntaxError: missing colon (Fix)</title><link>https://pythonbeginner.help/errors/syntaxerror-missing-colon-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/syntaxerror-missing-colon-fix/</guid><description>&lt;h1 id="syntaxerror-missing-colon-fix"&gt;SyntaxError: missing colon (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;code&gt;SyntaxError: missing colon&lt;/code&gt;. This page helps beginners find where the colon is missing, understand why Python needs it, and correct the code quickly.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Add a colon at the end of lines that start a block, such as &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;def&lt;/code&gt;, &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;try&lt;/code&gt;, &lt;code&gt;except&lt;/code&gt;, &lt;code&gt;finally&lt;/code&gt;, &lt;code&gt;with&lt;/code&gt;, and &lt;code&gt;match&lt;/code&gt;/&lt;code&gt;case&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Adult&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you add the colon, also make sure the next line is indented.&lt;/p&gt;</description></item><item><title>SyntaxError: unexpected EOF while parsing (Fix)</title><link>https://pythonbeginner.help/errors/syntaxerror-unexpected-eof-while-parsing-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/syntaxerror-unexpected-eof-while-parsing-fix/</guid><description>&lt;h1 id="syntaxerror-unexpected-eof-while-parsing-fix"&gt;SyntaxError: unexpected EOF while parsing (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;SyntaxError: unexpected EOF while parsing&lt;/code&gt; means Python reached the end of your file before the code was complete.&lt;/p&gt;
&lt;p&gt;This usually happens when something is missing, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a closing quote&lt;/li&gt;
&lt;li&gt;a closing parenthesis&lt;/li&gt;
&lt;li&gt;a closing bracket&lt;/li&gt;
&lt;li&gt;a closing brace&lt;/li&gt;
&lt;li&gt;the rest of an unfinished statement&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page will help you find the missing part, fix the syntax, and understand why Python shows this error.&lt;/p&gt;</description></item><item><title>TypeError vs ValueError in Python Explained</title><link>https://pythonbeginner.help/errors/typeerror-vs-valueerror-in-python-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-vs-valueerror-in-python-explained/</guid><description>&lt;h1 id="typeerror-vs-valueerror-in-python-explained"&gt;TypeError vs ValueError in Python Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;TypeError&lt;/code&gt; and &lt;code&gt;ValueError&lt;/code&gt; are two common Python errors that beginners often mix up.&lt;/p&gt;
&lt;p&gt;This page explains when Python raises &lt;code&gt;TypeError&lt;/code&gt; and when it raises &lt;code&gt;ValueError&lt;/code&gt;. It will help you tell them apart, read error messages more clearly, and choose the right fix.&lt;/p&gt;
&lt;h2 id="quick-answer"&gt;Quick answer &lt;a class="heading-anchor" href="#quick-answer" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="ne"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Wrong type was passed&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="ne"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Right type function, but bad value&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;TypeError&lt;/code&gt; when the &lt;strong&gt;kind of object&lt;/strong&gt; is wrong.&lt;/p&gt;</description></item><item><title>TypeError: 'bool' object is not iterable (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-bool-object-is-not-iterable-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-bool-object-is-not-iterable-fix/</guid><description>&lt;h1 id="typeerror-bool-object-is-not-iterable-fix"&gt;TypeError: &lt;code&gt;'bool' object is not iterable&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when Python expects something it can loop over, unpack, or check membership in, but gets &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt; instead.&lt;/p&gt;
&lt;p&gt;A boolean is only a single value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;True&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;False&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is &lt;strong&gt;not&lt;/strong&gt; a collection like a list, string, tuple, set, or dictionary.&lt;/p&gt;
&lt;p&gt;This guide shows what the error means, why it happens, and how to fix it based on what your variable should actually contain.&lt;/p&gt;</description></item><item><title>TypeError: 'dict' object is not callable (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-dict-object-is-not-callable-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-dict-object-is-not-callable-fix/</guid><description>&lt;h1 id="typeerror-dict-object-is-not-callable-fix"&gt;TypeError: &lt;code&gt;'dict' object is not callable&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;strong&gt;&lt;code&gt;TypeError: 'dict' object is not callable&lt;/code&gt;&lt;/strong&gt;. This page explains what the error means, the most common causes, and how to correct your code with simple examples.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This error often happens when you use parentheses &lt;code&gt;()&lt;/code&gt; with a dictionary. Use square brackets &lt;code&gt;[]&lt;/code&gt; to access a value by key.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;my_dict&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Wrong&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# value = my_dict(&amp;#39;a&amp;#39;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Correct&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;my_dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>TypeError: 'float' object cannot be interpreted as an integer (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-float-object-cannot-be-interpreted-as-an-integer-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-float-object-cannot-be-interpreted-as-an-integer-fix/</guid><description>&lt;h1 id="typeerror-float-object-cannot-be-interpreted-as-an-integer-fix"&gt;TypeError: &lt;code&gt;'float' object cannot be interpreted as an integer&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;code&gt;TypeError: 'float' object cannot be interpreted as an integer&lt;/code&gt;. This error happens when Python needs a whole number, but your code gives it a float instead.&lt;/p&gt;
&lt;p&gt;This page shows what the error means, where beginners usually see it, and the safest ways to fix it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;5.0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>TypeError: 'function' object is not iterable (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-function-object-is-not-iterable-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-function-object-is-not-iterable-fix/</guid><description>&lt;h1 id="typeerror-function-object-is-not-iterable-fix"&gt;TypeError: &lt;code&gt;'function' object is not iterable&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;strong&gt;&lt;code&gt;TypeError: 'function' object is not iterable&lt;/code&gt;&lt;/strong&gt;. This error usually means Python expected something it could loop over, but you gave it a function itself instead of the value returned by that function.&lt;/p&gt;
&lt;p&gt;In most cases, the fix is simple: &lt;strong&gt;call the function with parentheses&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_numbers&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;get_numbers&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This error often happens when you loop over a function name instead of the value returned by the function. Add parentheses if you meant to call the function.&lt;/p&gt;</description></item><item><title>TypeError: 'int' object is not iterable (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-int-object-is-not-iterable-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-int-object-is-not-iterable-fix/</guid><description>&lt;h1 id="typeerror-int-object-is-not-iterable-fix"&gt;TypeError: &lt;code&gt;'int' object is not iterable&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;code&gt;TypeError: 'int' object is not iterable&lt;/code&gt;. This page explains what the error means, why it happens, and the most common ways to correct your code.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Wrong&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Right: loop over a range&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;An integer is a single number, not a collection. If you want to loop a certain number of times, use &lt;a href="https://pythonbeginner.help/reference/python-range-function-explained/"&gt;&lt;code&gt;range()&lt;/code&gt;&lt;/a&gt;. If you meant to loop over values, make sure the variable is a list, tuple, string, or another iterable.&lt;/p&gt;</description></item><item><title>TypeError: 'list' object is not callable (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-list-object-is-not-callable-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-list-object-is-not-callable-fix/</guid><description>&lt;h1 id="typeerror-list-object-is-not-callable-fix"&gt;TypeError: &lt;code&gt;'list' object is not callable&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;strong&gt;&lt;code&gt;TypeError: 'list' object is not callable&lt;/code&gt;&lt;/strong&gt;. This page shows what the error means, the most common causes, and simple ways to correct your code.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# correct: use square brackets for indexing&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# not numbers(0)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This error usually happens when you use round brackets &lt;code&gt;()&lt;/code&gt; on a list, or when you overwrite a built-in function name like &lt;code&gt;list&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>TypeError: 'module' object is not callable (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-module-object-is-not-callable-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-module-object-is-not-callable-fix/</guid><description>&lt;h1 id="typeerror-module-object-is-not-callable-fix"&gt;TypeError: &lt;code&gt;'module' object is not callable&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when Python sees a &lt;strong&gt;module&lt;/strong&gt; where it expected something it can &lt;strong&gt;call&lt;/strong&gt; with parentheses.&lt;/p&gt;
&lt;p&gt;Beginners often run into this after writing code like &lt;code&gt;math(16)&lt;/code&gt; or &lt;code&gt;json(text)&lt;/code&gt;. The problem is that &lt;code&gt;math&lt;/code&gt; and &lt;code&gt;json&lt;/code&gt; are modules. They contain functions and classes, but the module itself is not a function.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;math&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Wrong:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# result = math(16)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Right:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;</description></item><item><title>TypeError: 'NoneType' object is not iterable (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-nonetype-object-is-not-iterable-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-nonetype-object-is-not-iterable-fix/</guid><description>&lt;h1 id="typeerror-nonetype-object-is-not-iterable-fix"&gt;TypeError: &lt;code&gt;'NoneType' object is not iterable&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;strong&gt;&lt;code&gt;TypeError: 'NoneType' object is not iterable&lt;/code&gt;&lt;/strong&gt;. This page explains what it means, why it happens, how to find where &lt;code&gt;None&lt;/code&gt; came from, and simple ways to fix it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_items&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use this only when an empty list makes sense. The real fix is to find out &lt;strong&gt;why the value is &lt;code&gt;None&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>TypeError: 'str' object cannot be interpreted as an integer (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-str-object-cannot-be-interpreted-as-an-integer-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-str-object-cannot-be-interpreted-as-an-integer-fix/</guid><description>&lt;h1 id="typeerror-str-object-cannot-be-interpreted-as-an-integer-fix"&gt;TypeError: &lt;code&gt;'str' object cannot be interpreted as an integer&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;strong&gt;&lt;code&gt;TypeError: 'str' object cannot be interpreted as an integer&lt;/code&gt;&lt;/strong&gt;. This page explains what the error means, common causes, and the fastest ways to correct your code.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;5&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This error happens when Python expects an integer, but you give it a string instead. Convert the string first if it contains a number.&lt;/p&gt;</description></item><item><title>TypeError: can only concatenate str (not "int") to str (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-can-only-concatenate-str-not-int-to-str-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-can-only-concatenate-str-not-int-to-str-fix/</guid><description>&lt;h1 id="typeerror-can-only-concatenate-str-not-int-to-str-fix"&gt;TypeError: can only concatenate str (not &amp;ldquo;int&amp;rdquo;) to str (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when Python tries to join a string and an integer with &lt;code&gt;+&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In Python, &lt;code&gt;+&lt;/code&gt; can join strings only when &lt;strong&gt;both values are strings&lt;/strong&gt;. If one value is text and the other is a number, Python raises a &lt;code&gt;TypeError&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Age: &amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# or&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Age: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Convert the integer to a string before concatenation, or use an f-string for cleaner output.&lt;/p&gt;</description></item><item><title>TypeError: cannot unpack non-iterable object (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-cannot-unpack-non-iterable-object-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-cannot-unpack-non-iterable-object-fix/</guid><description>&lt;h1 id="typeerror-cannot-unpack-non-iterable-object-fix"&gt;TypeError: cannot unpack non-iterable object (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when Python tries to split one value into multiple variables, but that value is not something Python can unpack.&lt;/p&gt;
&lt;p&gt;For example, Python can unpack a tuple like &lt;code&gt;(1, 2)&lt;/code&gt; into &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;. But it cannot unpack a single integer like &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Wrong:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# a, b = value&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Fix 1: assign to one variable&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Fix 2: unpack an actual iterable&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;pair&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pair&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;</description></item><item><title>TypeError: list indices must be integers or slices (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-list-indices-must-be-integers-or-slices-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-list-indices-must-be-integers-or-slices-fix/</guid><description>&lt;h1 id="typeerror-list-indices-must-be-integers-or-slices-fix"&gt;TypeError: list indices must be integers or slices (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;strong&gt;&lt;code&gt;TypeError: list indices must be integers or slices, not ...&lt;/code&gt;&lt;/strong&gt;. This error happens when you try to access a list with the wrong kind of value inside square brackets.&lt;/p&gt;
&lt;p&gt;This page explains:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what the error means&lt;/li&gt;
&lt;li&gt;why it happens&lt;/li&gt;
&lt;li&gt;the most common ways to fix it&lt;/li&gt;
&lt;li&gt;how to debug it quickly&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# If the index comes from input, convert it first:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;user_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Enter index: &amp;#34;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;user_index&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;List positions must be integers like &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt;, or slices like &lt;code&gt;[1:3]&lt;/code&gt;. Strings, floats, and other lists cannot be used as list indices.&lt;/p&gt;</description></item><item><title>TypeError: missing required positional argument (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-missing-required-positional-argument-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-missing-required-positional-argument-fix/</guid><description>&lt;h1 id="typeerror-missing-required-positional-argument-fix"&gt;TypeError: missing required positional argument (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when Python expects an argument, but your code does not provide it.&lt;/p&gt;
&lt;p&gt;It usually appears when you call a function or method with too few values. The message often tells you exactly which parameter is missing.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Sam&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# pass the required argument&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If a function expects one or more required positional arguments, you must provide them when calling it unless the function defines default values.&lt;/p&gt;</description></item><item><title>TypeError: sequence item 0 expected str instance (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-sequence-item-0-expected-str-instance-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-sequence-item-0-expected-str-instance-fix/</guid><description>&lt;h1 id="typeerror-sequence-item-0-expected-str-instance-fix"&gt;TypeError: sequence item 0 expected str instance (Fix)&lt;/h1&gt;
&lt;p&gt;This error usually appears when you use &lt;code&gt;str.join()&lt;/code&gt; on a list or other sequence that contains at least one non-string value.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;join()&lt;/code&gt; only works with strings. If your data contains integers, &lt;code&gt;None&lt;/code&gt;, floats, booleans, or other types, Python raises a &lt;code&gt;TypeError&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The good news is that this is usually easy to fix:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;find the non-string values&lt;/li&gt;
&lt;li&gt;convert them to strings&lt;/li&gt;
&lt;li&gt;or remove values that should not be joined&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;a&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;b&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34; &amp;#34;&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;</description></item><item><title>TypeError: unexpected keyword argument (Fix)</title><link>https://pythonbeginner.help/errors/typeerror-unexpected-keyword-argument-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/typeerror-unexpected-keyword-argument-fix/</guid><description>&lt;h1 id="typeerror-unexpected-keyword-argument-fix"&gt;TypeError: unexpected keyword argument (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when you call a function, method, or class constructor with a keyword name that it does not accept.&lt;/p&gt;
&lt;p&gt;In Python, a keyword argument is a named argument like &lt;code&gt;name=&amp;quot;Sam&amp;quot;&lt;/code&gt;. If the function expects &lt;code&gt;name&lt;/code&gt; but you pass &lt;code&gt;username&lt;/code&gt;, Python raises a &lt;code&gt;TypeError&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The good news is that this is usually easy to fix:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use the exact parameter name the function expects&lt;/li&gt;
&lt;li&gt;Or pass the value without a keyword if positional arguments are allowed&lt;/li&gt;
&lt;li&gt;Or update your own function definition if needed&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Sam&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# works&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# greet(username=&amp;#34;Sam&amp;#34;) # TypeError: unexpected keyword argument &amp;#39;username&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use the exact parameter name from the function definition or documentation.&lt;/p&gt;</description></item><item><title>UnboundLocalError vs NameError Explained</title><link>https://pythonbeginner.help/errors/unboundlocalerror-vs-nameerror-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/unboundlocalerror-vs-nameerror-explained/</guid><description>&lt;h1 id="unboundlocalerror-vs-nameerror-explained"&gt;UnboundLocalError vs NameError Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;UnboundLocalError&lt;/code&gt; and &lt;code&gt;NameError&lt;/code&gt; can look very similar at first.&lt;/p&gt;
&lt;p&gt;Both happen when Python has a problem with a variable name. But they do &lt;strong&gt;not&lt;/strong&gt; mean the same thing.&lt;/p&gt;
&lt;p&gt;This page helps you quickly tell the difference:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;NameError&lt;/code&gt; means Python cannot find the name at all&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UnboundLocalError&lt;/code&gt; means Python treats the name as a local variable, but you used it before it got a value&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are new to Python variables and scope, this difference can be confusing. The examples below show exactly what each error means and how to fix it.&lt;/p&gt;</description></item><item><title>UnboundLocalError: local variable referenced before assignment (Fix)</title><link>https://pythonbeginner.help/errors/unboundlocalerror-local-variable-referenced-before-assignment-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/unboundlocalerror-local-variable-referenced-before-assignment-fix/</guid><description>&lt;h1 id="unboundlocalerror-local-variable-referenced-before-assignment-fix"&gt;UnboundLocalError: local variable referenced before assignment (Fix)&lt;/h1&gt;
&lt;p&gt;Fix the Python error &lt;code&gt;UnboundLocalError: local variable referenced before assignment&lt;/code&gt;. This page explains what the error means, why Python raises it inside functions, and the safest ways to fix it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;show_count&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# works because we only read the global value&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;show_count&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you assign to a variable anywhere inside a function, Python treats it as local in that function. Use a parameter, return value, or &lt;code&gt;global&lt;/code&gt;/&lt;code&gt;nonlocal&lt;/code&gt; only when appropriate.&lt;/p&gt;</description></item><item><title>UnicodeDecodeError: 'utf-8' codec can't decode byte (Fix)</title><link>https://pythonbeginner.help/errors/unicodedecodeerror-utf-8-codec-cant-decode-byte-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/unicodedecodeerror-utf-8-codec-cant-decode-byte-fix/</guid><description>&lt;h1 id="unicodedecodeerror-utf-8-codec-cant-decode-byte-fix"&gt;UnicodeDecodeError: &lt;code&gt;'utf-8' codec can't decode byte&lt;/code&gt; (Fix)&lt;/h1&gt;
&lt;p&gt;If you see a Python error like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="ne"&gt;UnicodeDecodeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;utf-8&amp;#39;&lt;/span&gt; &lt;span class="n"&gt;codec&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;t decode byte ...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Python is trying to read data as UTF-8 text, but the bytes do not match valid UTF-8.&lt;/p&gt;
&lt;p&gt;This usually happens when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you open a text file with the wrong encoding&lt;/li&gt;
&lt;li&gt;a CSV file came from Excel or another Windows program&lt;/li&gt;
&lt;li&gt;you decode bytes from a file, download, or API using the wrong encoding&lt;/li&gt;
&lt;li&gt;the file is actually binary, not text&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In most cases, the fix is to open the file with the &lt;strong&gt;correct encoding&lt;/strong&gt; instead of relying on the default.&lt;/p&gt;</description></item><item><title>UnicodeEncodeError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/unicodeencodeerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/unicodeencodeerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="unicodeencodeerror-in-python-causes-and-fixes"&gt;UnicodeEncodeError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;UnicodeEncodeError&lt;/code&gt; happens when Python tries to convert text into bytes, but the target encoding cannot represent one or more characters.&lt;/p&gt;
&lt;p&gt;This often appears when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;writing text to a file&lt;/li&gt;
&lt;li&gt;printing text to a terminal&lt;/li&gt;
&lt;li&gt;sending text to another system&lt;/li&gt;
&lt;li&gt;calling &lt;code&gt;.encode()&lt;/code&gt; with the wrong encoding&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For beginners, the fastest fix is usually to use UTF-8 explicitly.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;café ☕&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;output.txt&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;w&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;utf-8&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Most fixes start by using UTF-8 explicitly. The error often happens when Python uses a narrower encoding like &lt;code&gt;ascii&lt;/code&gt; or &lt;code&gt;cp1252&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>ValueError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/valueerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/valueerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="valueerror-in-python-causes-and-fixes"&gt;ValueError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;ValueError&lt;/code&gt; is a common Python error for beginners.&lt;/p&gt;
&lt;p&gt;It means a function received a value of the correct type, but the actual content of that value is not valid for the operation.&lt;/p&gt;
&lt;p&gt;For example, &lt;code&gt;int()&lt;/code&gt; can convert strings to integers. But if the string does not contain a valid whole number, Python raises &lt;code&gt;ValueError&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;abc&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="ne"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Input must be a valid number&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;try-except&lt;/code&gt; when a value might have the right type but the wrong content, such as converting non-numeric text with &lt;code&gt;int()&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>ValueError when parsing input in Python (Fix)</title><link>https://pythonbeginner.help/errors/valueerror-when-parsing-input-in-python-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/valueerror-when-parsing-input-in-python-fix/</guid><description>&lt;h1 id="valueerror-when-parsing-input-in-python-fix"&gt;ValueError when parsing input in Python (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;ValueError&lt;/code&gt; often happens when your program reads text with &lt;code&gt;input()&lt;/code&gt; and then tries to convert that text into a number.&lt;/p&gt;
&lt;p&gt;This usually affects code that uses &lt;code&gt;int()&lt;/code&gt; or &lt;code&gt;float()&lt;/code&gt;. For example, the user might type letters instead of digits, leave the input blank, or enter a decimal when your code expects a whole number.&lt;/p&gt;
&lt;p&gt;This page shows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what the error means&lt;/li&gt;
&lt;li&gt;how to reproduce it&lt;/li&gt;
&lt;li&gt;simple ways to fix it&lt;/li&gt;
&lt;li&gt;how to prevent it in beginner-friendly code&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;user_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Enter a number: &amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;You entered:&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="ne"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Please enter a whole number only.&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;try-except&lt;/code&gt; when converting input with &lt;code&gt;int()&lt;/code&gt; or &lt;code&gt;float()&lt;/code&gt;. &lt;code&gt;strip()&lt;/code&gt; also helps remove accidental spaces.&lt;/p&gt;</description></item><item><title>ValueError: could not convert string to float (Fix)</title><link>https://pythonbeginner.help/errors/valueerror-could-not-convert-string-to-float-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/valueerror-could-not-convert-string-to-float-fix/</guid><description>&lt;h1 id="valueerror-could-not-convert-string-to-float-fix"&gt;ValueError: could not convert string to float (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when you call &lt;code&gt;float()&lt;/code&gt; with text that is not a valid number.&lt;/p&gt;
&lt;p&gt;It often appears when you read input from a user, a file, a CSV, or an API. The fix is usually to inspect the string, clean it if needed, and handle bad input safely.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Enter a number: &amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;,&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="ne"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Please enter a valid number, such as 3.14 or 10&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;strip()&lt;/code&gt; to remove extra spaces, clean the input if needed, and catch &lt;code&gt;ValueError&lt;/code&gt; when the text is not a valid decimal number.&lt;/p&gt;</description></item><item><title>ValueError: empty separator (Fix)</title><link>https://pythonbeginner.help/errors/valueerror-empty-separator-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/valueerror-empty-separator-fix/</guid><description>&lt;h1 id="valueerror-empty-separator-fix"&gt;ValueError: empty separator (Fix)&lt;/h1&gt;
&lt;p&gt;This page helps beginners fix the Python error &lt;code&gt;ValueError: empty separator&lt;/code&gt;. It explains why it happens, shows a small example that causes it, and gives simple ways to solve it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;apple,banana,orange&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;parts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;,&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# use a real separator&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;one two three&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# no argument splits on whitespace&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;apple&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;banana&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;orange&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;one&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;two&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;three&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Do not pass an empty string to &lt;code&gt;split()&lt;/code&gt;. Use a real separator like &lt;code&gt;&amp;quot;,&amp;quot;&lt;/code&gt; or leave the argument out to split on whitespace.&lt;/p&gt;</description></item><item><title>ValueError: invalid literal for int() with base 10 (Fix)</title><link>https://pythonbeginner.help/errors/valueerror-invalid-literal-for-int-with-base-10-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/valueerror-invalid-literal-for-int-with-base-10-fix/</guid><description>&lt;h1 id="valueerror-invalid-literal-for-int-with-base-10-fix"&gt;ValueError: invalid literal for int() with base 10 (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when Python tries to convert a value to an integer with &lt;code&gt;int()&lt;/code&gt;, but the value does not look like a valid whole number.&lt;/p&gt;
&lt;p&gt;This page shows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what the error means&lt;/li&gt;
&lt;li&gt;common examples that cause it&lt;/li&gt;
&lt;li&gt;why it happens&lt;/li&gt;
&lt;li&gt;simple ways to fix it safely&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want a broader explanation of exceptions, see &lt;a href="https://pythonbeginner.help/learn/python-errors-and-exceptions-explained/"&gt;Python errors and exceptions explained&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use this when you expect a whole number from text input:&lt;/p&gt;</description></item><item><title>ValueError: math domain error (Fix)</title><link>https://pythonbeginner.help/errors/valueerror-math-domain-error-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/valueerror-math-domain-error-fix/</guid><description>&lt;h1 id="valueerror-math-domain-error-fix"&gt;ValueError: math domain error (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;ValueError: math domain error&lt;/code&gt; happens when you pass a value to a function in Python’s &lt;code&gt;math&lt;/code&gt; module that is outside the valid input range.&lt;/p&gt;
&lt;p&gt;This usually happens with functions like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;math.sqrt()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;math.log()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;math.log10()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;math.asin()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;math.acos()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, &lt;code&gt;math.sqrt(-1)&lt;/code&gt; fails because the &lt;code&gt;math&lt;/code&gt; module expects a real number, and &lt;code&gt;-1&lt;/code&gt; is not a valid input for a real square root.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;math&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;x must be 0 or greater&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This error happens when you pass a value that is outside the valid range for a math function, such as &lt;code&gt;math.sqrt(-1)&lt;/code&gt; or &lt;code&gt;math.log(0)&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>ValueError: not enough values to unpack (Fix)</title><link>https://pythonbeginner.help/errors/valueerror-not-enough-values-to-unpack-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/valueerror-not-enough-values-to-unpack-fix/</guid><description>&lt;h1 id="valueerror-not-enough-values-to-unpack-fix"&gt;ValueError: not enough values to unpack (Fix)&lt;/h1&gt;
&lt;p&gt;This error happens when Python tries to unpack values into multiple variables, but there are fewer values than expected.&lt;/p&gt;
&lt;p&gt;A common message looks like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="ne"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;enough&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;unpack&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;got&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In this guide, you will learn what this means, why it happens, and how to fix it in common cases like lists, function returns, loops, and &lt;code&gt;split()&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Make sure the number of variables matches the number of values.&lt;/p&gt;</description></item><item><title>ValueError: substring not found (Fix)</title><link>https://pythonbeginner.help/errors/valueerror-substring-not-found-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/valueerror-substring-not-found-fix/</guid><description>&lt;h1 id="valueerror-substring-not-found-fix"&gt;ValueError: substring not found (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;ValueError: substring not found&lt;/code&gt; means Python could not find the piece of text you asked for inside a string.&lt;/p&gt;
&lt;p&gt;This error usually appears when you use string methods like &lt;code&gt;index()&lt;/code&gt; that expect a match. If the substring is missing, Python raises an error instead of returning a special value.&lt;/p&gt;
&lt;p&gt;This page shows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what the error means&lt;/li&gt;
&lt;li&gt;why it happens&lt;/li&gt;
&lt;li&gt;examples that cause it&lt;/li&gt;
&lt;li&gt;simple ways to fix it&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If the substring may be missing, check first before calling &lt;code&gt;index()&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>ValueError: too many values to unpack (Fix)</title><link>https://pythonbeginner.help/errors/valueerror-too-many-values-to-unpack-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/valueerror-too-many-values-to-unpack-fix/</guid><description>&lt;h1 id="valueerror-too-many-values-to-unpack-fix"&gt;ValueError: too many values to unpack (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;ValueError: too many values to unpack&lt;/code&gt; happens when Python tries to assign more values than your variables can hold.&lt;/p&gt;
&lt;p&gt;This usually appears when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you unpack a list or tuple into too few variables&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;for&lt;/code&gt; loop expects the wrong number of values&lt;/li&gt;
&lt;li&gt;a function returns more values than expected&lt;/li&gt;
&lt;li&gt;&lt;code&gt;split()&lt;/code&gt; gives you more parts than you planned for&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The fix is usually simple: make the number of variables match the number of values, or use starred unpacking to collect extras.&lt;/p&gt;</description></item><item><title>ZeroDivisionError in Python: Causes and Fixes</title><link>https://pythonbeginner.help/errors/zerodivisionerror-in-python-causes-and-fixes/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/zerodivisionerror-in-python-causes-and-fixes/</guid><description>&lt;h1 id="zerodivisionerror-in-python-causes-and-fixes"&gt;ZeroDivisionError in Python: Causes and Fixes&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;ZeroDivisionError&lt;/code&gt; happens when Python tries to divide a number by &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is a common beginner error. It usually means the value on the right side of &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;//&lt;/code&gt;, or &lt;code&gt;%&lt;/code&gt; became zero before the calculation ran.&lt;/p&gt;
&lt;p&gt;In this guide, you will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what &lt;code&gt;ZeroDivisionError&lt;/code&gt; means&lt;/li&gt;
&lt;li&gt;the common reasons it happens&lt;/li&gt;
&lt;li&gt;how to prevent it&lt;/li&gt;
&lt;li&gt;how to debug the value that became zero&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If the divisor might be &lt;code&gt;0&lt;/code&gt;, check it before dividing:&lt;/p&gt;</description></item><item><title>ZeroDivisionError: division by zero (Fix)</title><link>https://pythonbeginner.help/errors/zerodivisionerror-division-by-zero-fix/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/errors/zerodivisionerror-division-by-zero-fix/</guid><description>&lt;h1 id="zerodivisionerror-division-by-zero-fix"&gt;ZeroDivisionError: division by zero (Fix)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;ZeroDivisionError: division by zero&lt;/code&gt; happens when Python tries to divide by &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This page shows what the error means, why it happens, and the simplest ways to prevent or handle it.&lt;/p&gt;
&lt;h2 id="quick-fix"&gt;Quick fix &lt;a class="heading-anchor" href="#quick-fix" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Check the value before dividing. If zero is possible, handle that case first.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;denominator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;denominator&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;denominator&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Cannot divide by zero&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If the denominator is &lt;code&gt;0&lt;/code&gt;, the program avoids the division and prints a clear message instead.&lt;/p&gt;</description></item></channel></rss>