<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python Beginner Help</title><link>https://pythonbeginner.help/</link><description>Recent content on Python Beginner Help</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Wed, 17 Jun 2026 16:38:08 +0200</lastBuildDate><atom:link href="https://pythonbeginner.help/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>Basic Methods in Python Classes Explained</title><link>https://pythonbeginner.help/learn/basic-methods-in-python-classes-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/basic-methods-in-python-classes-explained/</guid><description>&lt;h1 id="basic-methods-in-python-classes-explained"&gt;Basic Methods in Python Classes Explained&lt;/h1&gt;
&lt;p&gt;Methods are one of the most important parts of Python classes.&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;method&lt;/strong&gt; is a function written inside a class. You use methods to describe actions that an object can perform. This page explains what methods are, why &lt;code&gt;self&lt;/code&gt; is used, and how to create and call simple instance methods.&lt;/p&gt;
&lt;p&gt;We will start with a one-line method and work up to methods that use and return object data.&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>datetime.now() Explained</title><link>https://pythonbeginner.help/standard-library/datetime.now-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/datetime.now-explained/</guid><description>&lt;h1 id="datetimenow-explained"&gt;&lt;code&gt;datetime.now()&lt;/code&gt; Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;datetime.now()&lt;/code&gt; gives you the current local date and time in Python.&lt;/p&gt;
&lt;p&gt;Beginners often use it when they want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;record the current time&lt;/li&gt;
&lt;li&gt;print today’s date&lt;/li&gt;
&lt;li&gt;create timestamps&lt;/li&gt;
&lt;li&gt;work with dates and times in programs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is important to know that &lt;code&gt;datetime.now()&lt;/code&gt; returns a &lt;strong&gt;&lt;code&gt;datetime&lt;/code&gt; object&lt;/strong&gt;, not a plain string. That means you can access parts of it like the year, month, day, or hour.&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;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&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;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&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;now&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;now&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&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;now&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;month&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;now&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;day&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 when you want the current local date and time as a &lt;code&gt;datetime&lt;/code&gt; object.&lt;/p&gt;</description></item><item><title>datetime.strftime() Explained</title><link>https://pythonbeginner.help/standard-library/datetime.strftime-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/datetime.strftime-explained/</guid><description>&lt;h1 id="datetimestrftime-explained"&gt;datetime.strftime() Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;datetime.strftime()&lt;/code&gt; formats a date or time object as a string.&lt;/p&gt;
&lt;p&gt;Use it when you want to control how a date or time looks, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;2025-04-22&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;04/22/2025&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;April 22, 2025&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;14:30:00&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This method is part of Python’s &lt;code&gt;datetime&lt;/code&gt; tools. It works with &lt;code&gt;datetime&lt;/code&gt;, &lt;code&gt;date&lt;/code&gt;, and &lt;code&gt;time&lt;/code&gt; objects. If you are new to the module, see the &lt;a href="https://pythonbeginner.help/standard-library/python-datetime-module-overview"&gt;Python datetime module overview&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&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;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&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;formatted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;%Y-%m-&lt;/span&gt;&lt;span class="si"&gt;%d&lt;/span&gt;&lt;span class="s2"&gt; %H:%M:%S&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;formatted&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;Example output:&lt;/p&gt;</description></item><item><title>datetime.strptime() Explained</title><link>https://pythonbeginner.help/standard-library/datetime.strptime-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/datetime.strptime-explained/</guid><description>&lt;h1 id="datetimestrptime-explained"&gt;&lt;code&gt;datetime.strptime()&lt;/code&gt; Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;datetime.strptime()&lt;/code&gt; turns a date or time &lt;strong&gt;string&lt;/strong&gt; into a real &lt;code&gt;datetime&lt;/code&gt; object.&lt;/p&gt;
&lt;p&gt;This is useful when your date comes from:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;user input&lt;/li&gt;
&lt;li&gt;a file&lt;/li&gt;
&lt;li&gt;a CSV&lt;/li&gt;
&lt;li&gt;an API response&lt;/li&gt;
&lt;li&gt;a log entry&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The important rule is simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the &lt;strong&gt;text must match the format string exactly&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page focuses on &lt;strong&gt;parsing strings into datetime objects&lt;/strong&gt;. If you want to go the other way and turn a datetime object into text, see &lt;a href="https://pythonbeginner.help/standard-library/datetime.strftime-explained"&gt;&lt;code&gt;datetime.strftime()&lt;/code&gt; explained&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Decorators in Python (Beginner Introduction)</title><link>https://pythonbeginner.help/learn/decorators-in-python-beginner-introduction/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/decorators-in-python-beginner-introduction/</guid><description>&lt;h1 id="decorators-in-python-beginner-introduction"&gt;Decorators in Python (Beginner Introduction)&lt;/h1&gt;
&lt;p&gt;Decorators can look confusing when you first see code like &lt;code&gt;@something&lt;/code&gt; above a function.&lt;/p&gt;
&lt;p&gt;This page explains the basic idea in simple terms. You will learn what a decorator is, why it is useful, how the &lt;code&gt;@&lt;/code&gt; syntax works, and how to read simple decorator examples without getting into advanced patterns.&lt;/p&gt;
&lt;p&gt;If decorators still feel unclear, it helps to first understand &lt;a href="https://pythonbeginner.help/learn/python-functions-explained/"&gt;Python functions&lt;/a&gt; and &lt;a href="https://pythonbeginner.help/learn/function-parameters-and-arguments-in-python/"&gt;function parameters and arguments&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Default and Keyword Arguments Explained</title><link>https://pythonbeginner.help/learn/default-and-keyword-arguments-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/default-and-keyword-arguments-explained/</guid><description>&lt;h1 id="default-and-keyword-arguments-explained"&gt;Default and Keyword Arguments Explained&lt;/h1&gt;
&lt;p&gt;Default arguments and keyword arguments make Python functions easier to call.&lt;/p&gt;
&lt;p&gt;They help you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;make some function inputs optional&lt;/li&gt;
&lt;li&gt;write clearer function calls&lt;/li&gt;
&lt;li&gt;avoid passing every value every time&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page explains what they are, how they work, and the main rules beginners should remember. If you are new to functions, start with &lt;a href="https://pythonbeginner.help/learn/python-functions-explained/"&gt;Python functions explained&lt;/a&gt; or &lt;a href="https://pythonbeginner.help/learn/function-parameters-and-arguments-in-python/"&gt;function parameters and arguments in Python&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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 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 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;message&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&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="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Hi&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;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="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Welcome&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;Output:&lt;/p&gt;</description></item><item><title>Dictionary Comprehensions Explained</title><link>https://pythonbeginner.help/learn/dictionary-comprehensions-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/dictionary-comprehensions-explained/</guid><description>&lt;h1 id="dictionary-comprehensions-explained"&gt;Dictionary Comprehensions Explained&lt;/h1&gt;
&lt;p&gt;A dictionary comprehension is a short way to create a dictionary in Python.&lt;/p&gt;
&lt;p&gt;It lets you build keys and values in one line instead of writing a full loop. This is useful when you want to transform existing data into a new dictionary.&lt;/p&gt;
&lt;p&gt;If you already know what a Python dictionary is, this is the next step toward writing shorter and cleaner code. If not, read &lt;a href="https://pythonbeginner.help/learn/python-dictionaries-explained"&gt;Python dictionaries explained&lt;/a&gt; first.&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>Function Parameters and Arguments in Python</title><link>https://pythonbeginner.help/learn/function-parameters-and-arguments-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/function-parameters-and-arguments-in-python/</guid><description>&lt;h1 id="function-parameters-and-arguments-in-python"&gt;Function Parameters and Arguments in Python&lt;/h1&gt;
&lt;p&gt;Function parameters and arguments are closely related, but they are not the same thing.&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;parameter&lt;/strong&gt; is a name written in a function definition. An &lt;strong&gt;argument&lt;/strong&gt; is the actual value you pass to the function when you call it.&lt;/p&gt;
&lt;p&gt;Understanding this difference makes it much easier to read Python functions, write your own functions, and fix function call errors.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;Maya&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;ul&gt;
&lt;li&gt;&lt;strong&gt;Parameter:&lt;/strong&gt; &lt;code&gt;name&lt;/code&gt; in the function definition&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Argument:&lt;/strong&gt; &lt;code&gt;&amp;quot;Maya&amp;quot;&lt;/code&gt; in the function call&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="what-this-page-teaches"&gt;What this page teaches &lt;a class="heading-anchor" href="#what-this-page-teaches" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;By the end of this page, you should understand that:&lt;/p&gt;</description></item><item><title>Generators in Python Explained</title><link>https://pythonbeginner.help/learn/generators-in-python-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/generators-in-python-explained/</guid><description>&lt;h1 id="generators-in-python-explained"&gt;Generators in Python Explained&lt;/h1&gt;
&lt;p&gt;Generators let you produce values one at a time instead of building a full list all at once.&lt;/p&gt;
&lt;p&gt;This is useful when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you have many values&lt;/li&gt;
&lt;li&gt;you only need to loop through them once&lt;/li&gt;
&lt;li&gt;you want to create values only when needed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A Python function becomes a generator function when it uses &lt;code&gt;yield&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The sections below explain how &lt;code&gt;yield&lt;/code&gt; pauses a function and how generators differ from regular functions and lists.&lt;/p&gt;</description></item><item><title>How Import Works in Python</title><link>https://pythonbeginner.help/learn/how-import-works-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/how-import-works-in-python/</guid><description>&lt;h1 id="how-import-works-in-python"&gt;How Import Works in Python&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;import&lt;/code&gt; lets you use code from another Python file or from Python’s built-in and installed modules.&lt;/p&gt;
&lt;p&gt;This is one of the most important Python basics. Once you understand how &lt;code&gt;import&lt;/code&gt; works, it becomes much easier to read other people’s code and organize your own code into separate files.&lt;/p&gt;
&lt;p&gt;Knowing the few &lt;code&gt;import&lt;/code&gt; forms also makes it clear, at a glance, where every function in a program actually comes from.&lt;/p&gt;</description></item><item><title>How to Access Values in a Dictionary in Python</title><link>https://pythonbeginner.help/how-to/how-to-access-values-in-a-dictionary-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-access-values-in-a-dictionary-in-python/</guid><description>&lt;h1 id="how-to-access-values-in-a-dictionary-in-python"&gt;How to Access Values in a Dictionary in Python&lt;/h1&gt;
&lt;p&gt;A Python dictionary stores data as &lt;strong&gt;key-value pairs&lt;/strong&gt;. To get a value, you use its key.&lt;/p&gt;
&lt;p&gt;This page shows the most common ways to access dictionary values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Direct access with square brackets&lt;/li&gt;
&lt;li&gt;Safer access with &lt;code&gt;get()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Checking whether a key exists&lt;/li&gt;
&lt;li&gt;Accessing nested dictionary values&lt;/li&gt;
&lt;li&gt;Looping through all key-value pairs&lt;/li&gt;
&lt;/ul&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="n"&gt;person&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 class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&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="c1"&gt;# Ana&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;person&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;# 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;person&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;city&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use square brackets when the key &lt;strong&gt;must exist&lt;/strong&gt;. Use &lt;code&gt;get()&lt;/code&gt; when the key &lt;strong&gt;might be missing&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>How to Add a Key to a Dictionary in Python</title><link>https://pythonbeginner.help/how-to/how-to-add-a-key-to-a-dictionary-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-add-a-key-to-a-dictionary-in-python/</guid><description>&lt;h1 id="how-to-add-a-key-to-a-dictionary-in-python"&gt;How to Add a Key to a Dictionary in Python&lt;/h1&gt;
&lt;p&gt;If you want to add a new key to a Python dictionary, the simplest way is to assign a value with square brackets.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add one new key-value pair to a dictionary&lt;/li&gt;
&lt;li&gt;Update a key if it already exists&lt;/li&gt;
&lt;li&gt;Choose between bracket assignment and &lt;code&gt;update()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Understand what happens when the key is already present&lt;/li&gt;
&lt;/ul&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="n"&gt;person&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 class="n"&gt;person&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="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&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;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="c1"&gt;# {&amp;#39;name&amp;#39;: &amp;#39;Ana&amp;#39;, &amp;#39;age&amp;#39;: 25}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use square brackets with a new key name. If the key already exists, the value is replaced.&lt;/p&gt;</description></item><item><title>How to Add an Item to a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-add-an-item-to-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-add-an-item-to-a-list-in-python/</guid><description>&lt;h1 id="how-to-add-an-item-to-a-list-in-python"&gt;How to Add an Item to a List in Python&lt;/h1&gt;
&lt;p&gt;If you want to add values to a Python list, the method you use depends on what result you want.&lt;/p&gt;
&lt;p&gt;This page shows the simplest ways to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add one item to the end of a list&lt;/li&gt;
&lt;li&gt;Add multiple items to a list&lt;/li&gt;
&lt;li&gt;Add an item at a specific position&lt;/li&gt;
&lt;li&gt;Understand when to use &lt;code&gt;append()&lt;/code&gt;, &lt;code&gt;extend()&lt;/code&gt;, or &lt;code&gt;insert()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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="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="n"&gt;numbers&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="mi"&gt;4&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# [1, 2, 3, 4]&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;append()&lt;/code&gt; to add one item to the end of a list.&lt;/p&gt;</description></item><item><title>How to Add Methods to a Class in Python</title><link>https://pythonbeginner.help/how-to/how-to-add-methods-to-a-class-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-add-methods-to-a-class-in-python/</guid><description>&lt;h1 id="how-to-add-methods-to-a-class-in-python"&gt;How to Add Methods to a Class in Python&lt;/h1&gt;
&lt;p&gt;A method is a function defined inside a class. In Python, you add methods to describe what an object can do.&lt;/p&gt;
&lt;p&gt;On this page, you will learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Define a method inside a class&lt;/li&gt;
&lt;li&gt;Call that method on an object&lt;/li&gt;
&lt;li&gt;Pass extra data into a method&lt;/li&gt;
&lt;li&gt;Return a value from a method&lt;/li&gt;
&lt;li&gt;Understand why the first parameter is usually &lt;code&gt;self&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&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;def&lt;/span&gt; &lt;span class="nf"&gt;bark&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&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;Woof!&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="n"&gt;my_dog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Dog&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_dog&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bark&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>How to Append to a File in Python</title><link>https://pythonbeginner.help/how-to/how-to-append-to-a-file-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-append-to-a-file-in-python/</guid><description>&lt;h1 id="how-to-append-to-a-file-in-python"&gt;How to Append to a File in Python&lt;/h1&gt;
&lt;p&gt;If you want to add text to an existing file without deleting what is already there, use &lt;strong&gt;append mode&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In Python, append mode is &lt;code&gt;&amp;quot;a&amp;quot;&lt;/code&gt; in the &lt;code&gt;open()&lt;/code&gt; function. It writes new content at the end of the file instead of replacing the old content.&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;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;notes.txt&amp;#34;&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="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="s2"&gt;&amp;#34;New line of text&lt;/span&gt;&lt;span class="se"&gt;\n&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;Open the file with mode &lt;code&gt;&amp;quot;a&amp;quot;&lt;/code&gt; to append. This adds text at the end instead of replacing the file.&lt;/p&gt;</description></item><item><title>How to Catch Multiple Exceptions in Python</title><link>https://pythonbeginner.help/how-to/how-to-catch-multiple-exceptions-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-catch-multiple-exceptions-in-python/</guid><description>&lt;h1 id="how-to-catch-multiple-exceptions-in-python"&gt;How to Catch Multiple Exceptions in Python&lt;/h1&gt;
&lt;p&gt;Sometimes the same piece of Python code can fail in more than one way.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;converting text to a number can raise a &lt;code&gt;ValueError&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;dividing by that number can raise a &lt;code&gt;ZeroDivisionError&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In cases like this, you can catch multiple exceptions with one &lt;code&gt;except&lt;/code&gt; block.&lt;/p&gt;
&lt;p&gt;This page shows you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;how to catch more than one exception in a &lt;code&gt;try&lt;/code&gt; block&lt;/li&gt;
&lt;li&gt;the correct syntax for grouped exceptions&lt;/li&gt;
&lt;li&gt;when to use one &lt;code&gt;except&lt;/code&gt; block&lt;/li&gt;
&lt;li&gt;when separate &lt;code&gt;except&lt;/code&gt; blocks are better&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;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="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;number&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="p"&gt;(&lt;/span&gt;&lt;span class="ne"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ne"&gt;ZeroDivisionError&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;e&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="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Error: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&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;figure class="diagram" role="group" aria-label="One except block can handle several exception types."&gt;
&lt;svg width="802" height="166" viewBox="0 0 802 166" class="d-svg" xmlns="http://www.w3.org/2000/svg" role="img"&gt;
 &lt;defs&gt;&lt;marker id="flowarrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"&gt;&lt;path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/&gt;&lt;/marker&gt;&lt;/defs&gt;&lt;rect x="229" y="8" width="348" height="44" rx="8" class="d-node-try"/&gt;
 &lt;text x="403" y="30" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;try: int(user_input) then 10 / number&lt;/text&gt;&lt;path d="M229 30 H194 V110" class="d-edge" marker-end="url(#flowarrow)" fill="none"/&gt;
 &lt;text x="293" y="72" class="d-edge-label d-edge-ok"&gt;no error&lt;/text&gt;
 &lt;path d="M577 30 H612 V110" class="d-edge" marker-end="url(#flowarrow)" fill="none"/&gt;
 &lt;text x="473" y="72" class="d-edge-label d-edge-err"&gt;error raised&lt;/text&gt;&lt;rect x="20" y="110" width="348" height="44" rx="8" class="d-node"/&gt;
 &lt;text x="194" y="132" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;continue&lt;/text&gt;&lt;rect x="438" y="110" width="348" height="44" rx="8" class="d-node-err"/&gt;
 &lt;text x="612" y="132" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;except: catch ValueError or ZeroDivisionError&lt;/text&gt;&lt;/svg&gt;&lt;figcaption&gt;One except block can handle several exception types.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Use parentheses to catch multiple exception types in one &lt;code&gt;except&lt;/code&gt; block.&lt;/p&gt;</description></item><item><title>How to Check if a File Exists in Python</title><link>https://pythonbeginner.help/how-to/how-to-check-if-a-file-exists-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-check-if-a-file-exists-in-python/</guid><description>&lt;h1 id="how-to-check-if-a-file-exists-in-python"&gt;How to Check if a File Exists in Python&lt;/h1&gt;
&lt;p&gt;Learn the simplest ways to check whether a file exists before reading, writing, renaming, or deleting it in Python.&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="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&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;file_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;data.txt&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;if&lt;/span&gt; &lt;span class="n"&gt;file_path&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;file_path&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;File exists&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;File does not exist&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;exists()&lt;/code&gt; to check whether the path is there, and &lt;code&gt;is_file()&lt;/code&gt; to make sure it is a file, not a folder.&lt;/p&gt;
&lt;h2 id="what-this-page-helps-you-do"&gt;What this page helps you do &lt;a class="heading-anchor" href="#what-this-page-helps-you-do" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Check whether a file is present before using it&lt;/li&gt;
&lt;li&gt;Avoid errors when opening or deleting files&lt;/li&gt;
&lt;li&gt;Understand the difference between a file path and a directory path&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="best-beginner-option-pathlib"&gt;Best beginner option: &lt;code&gt;pathlib&lt;/code&gt; &lt;a class="heading-anchor" href="#best-beginner-option-pathlib" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;For new Python code, &lt;code&gt;pathlib&lt;/code&gt; is usually the easiest option to read and understand.&lt;/p&gt;</description></item><item><title>How to Check if a Key Exists in a Dictionary in Python</title><link>https://pythonbeginner.help/how-to/how-to-check-if-a-key-exists-in-a-dictionary-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-check-if-a-key-exists-in-a-dictionary-in-python/</guid><description>&lt;h1 id="how-to-check-if-a-key-exists-in-a-dictionary-in-python"&gt;How to Check if a Key Exists in a Dictionary in Python&lt;/h1&gt;
&lt;p&gt;Learn the simplest ways to check whether a dictionary contains a key in Python. This page focuses on practical lookup patterns beginners use most often.&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="n"&gt;user&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 class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&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="s2"&gt;&amp;#34;name&amp;#34;&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;user&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 exists&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 does not exist&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 the &lt;code&gt;in&lt;/code&gt; operator for the clearest and most common solution.&lt;/p&gt;
&lt;h2 id="what-this-page-helps-you-do"&gt;What this page helps you do &lt;a class="heading-anchor" href="#what-this-page-helps-you-do" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Check whether a dictionary has a specific key&lt;/li&gt;
&lt;li&gt;Avoid &lt;code&gt;KeyError&lt;/code&gt; when reading dictionary values&lt;/li&gt;
&lt;li&gt;Choose between &lt;code&gt;in&lt;/code&gt;, &lt;code&gt;get()&lt;/code&gt;, and &lt;code&gt;try-except&lt;/code&gt; for different situations&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="best-method-for-most-cases-use-in"&gt;Best method for most cases: use &lt;code&gt;in&lt;/code&gt; &lt;a class="heading-anchor" href="#best-method-for-most-cases-use-in" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In Python, the best way to check whether a dictionary contains a key is:&lt;/p&gt;</description></item><item><title>How to Check if a String Contains a Substring in Python</title><link>https://pythonbeginner.help/how-to/how-to-check-if-a-string-contains-a-substring-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-check-if-a-string-contains-a-substring-in-python/</guid><description>&lt;h1 id="how-to-check-if-a-string-contains-a-substring-in-python"&gt;How to Check if a String Contains a Substring in Python&lt;/h1&gt;
&lt;p&gt;If you want to check whether one piece of text appears inside another piece of text in Python, there are a few simple ways to do it.&lt;/p&gt;
&lt;p&gt;For beginners, the best option is usually the &lt;code&gt;in&lt;/code&gt; operator. It is easy to read, easy to write, and works well when you only need a yes-or-no answer.&lt;/p&gt;
&lt;p&gt;This page shows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;how to check if a smaller string exists inside a larger string&lt;/li&gt;
&lt;li&gt;the simplest beginner-friendly method first&lt;/li&gt;
&lt;li&gt;how case-sensitive matching works&lt;/li&gt;
&lt;li&gt;when to use &lt;code&gt;in&lt;/code&gt;, &lt;code&gt;find()&lt;/code&gt;, and &lt;code&gt;index()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Hello, world!&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;substring&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;world&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;substring&lt;/span&gt; &lt;span class="ow"&gt;in&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="s2"&gt;&amp;#34;Found&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;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;Output:&lt;/p&gt;</description></item><item><title>How to Check if a Value Exists in a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-check-if-a-value-exists-in-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-check-if-a-value-exists-in-a-list-in-python/</guid><description>&lt;h1 id="how-to-check-if-a-value-exists-in-a-list-in-python"&gt;How to Check if a Value Exists in a List in Python&lt;/h1&gt;
&lt;p&gt;If you want to check whether a value is inside a Python list, the simplest solution is the &lt;code&gt;in&lt;/code&gt; operator.&lt;/p&gt;
&lt;p&gt;This is the most common beginner-friendly way to test list membership. It works for strings, numbers, and other values stored in a list.&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="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;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;orange&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;if&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&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="s2"&gt;&amp;#34;Found&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;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;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="n"&gt;Found&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;in&lt;/code&gt; for a simple membership check. It returns &lt;code&gt;True&lt;/code&gt; if the value is present, otherwise &lt;code&gt;False&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>How to Convert Dictionary to JSON in Python</title><link>https://pythonbeginner.help/how-to/how-to-convert-dictionary-to-json-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-convert-dictionary-to-json-in-python/</guid><description>&lt;h1 id="how-to-convert-dictionary-to-json-in-python"&gt;How to Convert Dictionary to JSON in Python&lt;/h1&gt;
&lt;p&gt;If you want to turn a Python dictionary into JSON, use the built-in &lt;code&gt;json&lt;/code&gt; module.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;json.dumps()&lt;/code&gt; when you want a JSON &lt;strong&gt;string&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;json.dump()&lt;/code&gt; when you want to write JSON &lt;strong&gt;to a file&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page shows both methods with simple examples.&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="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&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;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;Alice&amp;#34;&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;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;active&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&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="n"&gt;json_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&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&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;json_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;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="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;Alice&amp;#34;&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;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;active&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;true&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;json.dumps()&lt;/code&gt; when you want a JSON string. Use &lt;code&gt;json.dump()&lt;/code&gt; when you want to save JSON directly to a file.&lt;/p&gt;</description></item><item><title>How to Convert Int to String in Python</title><link>https://pythonbeginner.help/how-to/how-to-convert-int-to-string-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-convert-int-to-string-in-python/</guid><description>&lt;h1 id="how-to-convert-int-to-string-in-python"&gt;How to Convert Int to String in Python&lt;/h1&gt;
&lt;p&gt;If you need to turn a whole number into text in Python, use &lt;code&gt;str()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is common when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;combining numbers with text&lt;/li&gt;
&lt;li&gt;joining numbers into one string&lt;/li&gt;
&lt;li&gt;writing numbers as text in messages or files&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In Python:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;an &lt;strong&gt;int&lt;/strong&gt; is a whole number like &lt;code&gt;5&lt;/code&gt; or &lt;code&gt;42&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;a &lt;strong&gt;string&lt;/strong&gt; is text like &lt;code&gt;&amp;quot;5&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;hello&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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="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="n"&gt;text&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="nb"&gt;print&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="nb"&gt;type&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;Output:&lt;/p&gt;</description></item><item><title>How to Convert String to Float in Python</title><link>https://pythonbeginner.help/how-to/how-to-convert-string-to-float-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-convert-string-to-float-in-python/</guid><description>&lt;h1 id="how-to-convert-string-to-float-in-python"&gt;How to Convert String to Float in Python&lt;/h1&gt;
&lt;p&gt;To convert a string to a float in Python, use the built-in &lt;code&gt;float()&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;This is useful when you have text like &lt;code&gt;&amp;quot;3.14&amp;quot;&lt;/code&gt; and want to turn it into a number you can calculate with. It is also common when working with &lt;code&gt;input()&lt;/code&gt;, form data, or values read from files.&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="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;3.14&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;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&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;</description></item><item><title>How to Convert String to Int in Python</title><link>https://pythonbeginner.help/how-to/how-to-convert-string-to-int-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-convert-string-to-int-in-python/</guid><description>&lt;h1 id="how-to-convert-string-to-int-in-python"&gt;How to Convert String to Int in Python&lt;/h1&gt;
&lt;p&gt;If you have text like &lt;code&gt;&amp;quot;123&amp;quot;&lt;/code&gt; and want to use it as a number, Python gives you a simple tool: &lt;code&gt;int()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This page shows you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;how to convert a string to an integer&lt;/li&gt;
&lt;li&gt;when &lt;code&gt;int()&lt;/code&gt; works&lt;/li&gt;
&lt;li&gt;how to handle invalid input safely&lt;/li&gt;
&lt;li&gt;what to do with spaces, signs, and decimal strings&lt;/li&gt;
&lt;/ul&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="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;123&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="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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;</description></item><item><title>How to Convert User Input to Numbers in Python</title><link>https://pythonbeginner.help/how-to/how-to-convert-user-input-to-numbers-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-convert-user-input-to-numbers-in-python/</guid><description>&lt;h1 id="how-to-convert-user-input-to-numbers-in-python"&gt;How to Convert User Input to Numbers in Python&lt;/h1&gt;
&lt;p&gt;When you use Python’s &lt;a href="https://pythonbeginner.help/reference/python-input-function-explained"&gt;&lt;code&gt;input()&lt;/code&gt; function&lt;/a&gt;, the value you get back is always text.&lt;/p&gt;
&lt;p&gt;That means if a user types &lt;code&gt;25&lt;/code&gt;, Python stores it as the string &lt;code&gt;&amp;quot;25&amp;quot;&lt;/code&gt;, not the number &lt;code&gt;25&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Convert &lt;code&gt;input()&lt;/code&gt; values to &lt;code&gt;int&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Convert &lt;code&gt;input()&lt;/code&gt; values to &lt;code&gt;float&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Understand why &lt;code&gt;input()&lt;/code&gt; returns a string&lt;/li&gt;
&lt;li&gt;Handle bad input without crashing&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;age&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 your 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="n"&gt;price&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="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Enter the price: &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="nb"&gt;print&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 class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&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-int-function-explained"&gt;&lt;code&gt;int()&lt;/code&gt;&lt;/a&gt; for whole numbers and &lt;a href="https://pythonbeginner.help/reference/python-float-function-explained"&gt;&lt;code&gt;float()&lt;/code&gt;&lt;/a&gt; for decimal numbers. &lt;code&gt;input()&lt;/code&gt; returns text, so math will not work until you convert it.&lt;/p&gt;</description></item><item><title>How to Copy a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-copy-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-copy-a-list-in-python/</guid><description>&lt;h1 id="how-to-copy-a-list-in-python"&gt;How to Copy a List in Python&lt;/h1&gt;
&lt;p&gt;If you want to copy a list in Python, the safest beginner-friendly choice is usually &lt;code&gt;list.copy()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This page shows you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;how to copy a list without changing the original list object&lt;/li&gt;
&lt;li&gt;which copy method to use for common cases&lt;/li&gt;
&lt;li&gt;why some copied lists still affect each other&lt;/li&gt;
&lt;li&gt;when you need a deep copy instead of a normal copy&lt;/li&gt;
&lt;/ul&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="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="n"&gt;copy_numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;copy&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="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&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;copy_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;numbers&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;copy_numbers&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>How to Create a Class in Python</title><link>https://pythonbeginner.help/how-to/how-to-create-a-class-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-create-a-class-in-python/</guid><description>&lt;h1 id="how-to-create-a-class-in-python"&gt;How to Create a Class in Python&lt;/h1&gt;
&lt;p&gt;If you want to group related data and actions together, a class is a good tool to use.&lt;/p&gt;
&lt;p&gt;This page shows you how to create your first Python class step by step. You will learn the basic class structure, how to add attributes, how to add methods, and how to create objects from the class.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&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;def&lt;/span&gt; &lt;span class="fm"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&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 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 class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&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;name&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;age&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;bark&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&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="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&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;says woof&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="n"&gt;my_dog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Max&amp;#34;&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;my_dog&lt;/span&gt;&lt;span class="o"&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="n"&gt;my_dog&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bark&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>How to Create a Directory in Python</title><link>https://pythonbeginner.help/how-to/how-to-create-a-directory-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-create-a-directory-in-python/</guid><description>&lt;h1 id="how-to-create-a-directory-in-python"&gt;How to Create a Directory in Python&lt;/h1&gt;
&lt;p&gt;If you want to create a new folder in Python, the safest beginner-friendly option is usually the standard library &lt;code&gt;pathlib&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;In this guide, you will learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a single directory in Python&lt;/li&gt;
&lt;li&gt;Create nested directories when parent folders do not exist&lt;/li&gt;
&lt;li&gt;Avoid errors when a directory already exists&lt;/li&gt;
&lt;li&gt;Choose between &lt;code&gt;pathlib&lt;/code&gt; and &lt;code&gt;os.mkdir()&lt;/code&gt; / &lt;code&gt;os.makedirs()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&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="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;my_folder&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;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exist_ok&lt;/span&gt;&lt;span class="o"&gt;=&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This creates the folder if it does not exist. If it already exists, Python does nothing.&lt;/p&gt;</description></item><item><title>How to Create a Simple Function in Python</title><link>https://pythonbeginner.help/how-to/how-to-create-a-simple-function-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-create-a-simple-function-in-python/</guid><description>&lt;h1 id="how-to-create-a-simple-function-in-python"&gt;How to Create a Simple Function in Python&lt;/h1&gt;
&lt;p&gt;A Python function lets you group code into a reusable block. This page shows the simplest working pattern first: define a function, then call it.&lt;/p&gt;
&lt;p&gt;You will also learn how to avoid common beginner mistakes like missing parentheses or bad indentation. Once this basic pattern makes sense, it becomes much easier to learn &lt;a href="https://pythonbeginner.help/learn/python-functions-explained"&gt;Python functions explained&lt;/a&gt;, parameters, and return values.&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;def&lt;/span&gt; &lt;span class="nf"&gt;say_hello&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;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;say_hello&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;def&lt;/code&gt; to create the function, indent the code inside it, then call the function by writing its name with parentheses.&lt;/p&gt;</description></item><item><title>How to Create an Object in Python</title><link>https://pythonbeginner.help/how-to/how-to-create-an-object-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-create-an-object-in-python/</guid><description>&lt;h1 id="how-to-create-an-object-in-python"&gt;How to Create an Object in Python&lt;/h1&gt;
&lt;p&gt;To create an object in Python, you first define a class, then call the class name like a function.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create an object from a class&lt;/li&gt;
&lt;li&gt;Understand the difference between the class name and the object variable&lt;/li&gt;
&lt;li&gt;Pass starting values when creating an object&lt;/li&gt;
&lt;li&gt;Use the object&amp;rsquo;s data and methods right away&lt;/li&gt;
&lt;/ul&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;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&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;def&lt;/span&gt; &lt;span class="fm"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&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="bp"&gt;self&lt;/span&gt;&lt;span class="o"&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;name&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;my_dog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Max&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;my_dog&lt;/span&gt;&lt;span class="o"&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;</description></item><item><title>How to Create and Use a Virtual Environment in Python</title><link>https://pythonbeginner.help/how-to/how-to-create-and-use-a-virtual-environment-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-create-and-use-a-virtual-environment-in-python/</guid><description>&lt;h1 id="how-to-create-and-use-a-virtual-environment-in-python"&gt;How to Create and Use a Virtual Environment in Python&lt;/h1&gt;
&lt;p&gt;A virtual environment lets you create an isolated Python setup for one project.&lt;/p&gt;
&lt;p&gt;This is useful when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;install packages without affecting other projects&lt;/li&gt;
&lt;li&gt;keep project dependencies separate&lt;/li&gt;
&lt;li&gt;avoid version conflicts between libraries&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On this page, you will learn how to create a virtual environment, activate it, install packages inside it, and leave it when you are done.&lt;/p&gt;</description></item><item><title>How to Debug Python Code (Beginner Guide)</title><link>https://pythonbeginner.help/how-to/how-to-debug-python-code-beginner-guide/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-debug-python-code-beginner-guide/</guid><description>&lt;h1 id="how-to-debug-python-code-beginner-guide"&gt;How to Debug Python Code (Beginner Guide)&lt;/h1&gt;
&lt;p&gt;Debugging means finding out &lt;strong&gt;why your Python code is not doing what you expect&lt;/strong&gt; and then fixing it step by step.&lt;/p&gt;
&lt;p&gt;This guide shows a simple process beginners can use to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;understand what debugging means&lt;/li&gt;
&lt;li&gt;find the line causing a problem&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;print()&lt;/code&gt; and traceback messages&lt;/li&gt;
&lt;li&gt;fix common mistakes without guessing&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The goal is not to use advanced tools. The goal is to help you build a &lt;strong&gt;repeatable debugging process&lt;/strong&gt; you can use in any Python program.&lt;/p&gt;</description></item><item><title>How to Delete a File in Python</title><link>https://pythonbeginner.help/how-to/how-to-delete-a-file-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-delete-a-file-in-python/</guid><description>&lt;h1 id="how-to-delete-a-file-in-python"&gt;How to Delete a File in Python&lt;/h1&gt;
&lt;p&gt;If you want to delete a file in Python, the most common way is to use &lt;code&gt;os.remove()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For beginners, the safest approach is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;store the file path in a variable&lt;/li&gt;
&lt;li&gt;check whether the file exists&lt;/li&gt;
&lt;li&gt;delete it only if it is really there&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This helps you avoid common errors like &lt;code&gt;FileNotFoundError&lt;/code&gt;.&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="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;file_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;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_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="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_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="s2"&gt;&amp;#34;File deleted&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;File does not exist&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;os.remove()&lt;/code&gt; to delete a file. Check that the path exists first to avoid a &lt;code&gt;FileNotFoundError&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>How to Exit a Program in Python</title><link>https://pythonbeginner.help/how-to/how-to-exit-a-program-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-exit-a-program-in-python/</guid><description>&lt;h1 id="how-to-exit-a-program-in-python"&gt;How to Exit a Program in Python&lt;/h1&gt;
&lt;p&gt;Sometimes you want a Python program to stop on purpose.&lt;/p&gt;
&lt;p&gt;This page shows the main ways to do that, when to use each one, and what mistakes to avoid. You will also see the difference between stopping a loop, leaving a function, and ending the whole script.&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="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;sys&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Starting program&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;sys&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exit&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 will not run&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;sys.exit()&lt;/code&gt; when you want to stop the program early. It raises &lt;code&gt;SystemExit&lt;/code&gt; and ends the script unless it is caught.&lt;/p&gt;</description></item><item><title>How to Filter a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-filter-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-filter-a-list-in-python/</guid><description>&lt;h1 id="how-to-filter-a-list-in-python"&gt;How to Filter a List in Python&lt;/h1&gt;
&lt;p&gt;Filtering a list means keeping only the items that match a rule.&lt;/p&gt;
&lt;p&gt;For example, you might want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;keep only even numbers&lt;/li&gt;
&lt;li&gt;keep only names longer than 4 letters&lt;/li&gt;
&lt;li&gt;remove empty strings&lt;/li&gt;
&lt;li&gt;keep only dictionaries where &lt;code&gt;age &amp;gt;= 18&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In Python, the most common way to do this is with a &lt;strong&gt;list comprehension&lt;/strong&gt;. You can also use the built-in &lt;code&gt;filter()&lt;/code&gt; function.&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="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 class="mi"&gt;4&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 class="mi"&gt;6&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;even_numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&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;numbers&lt;/span&gt; &lt;span class="k"&gt;if&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;2&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;even_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="c1"&gt;# Output: [2, 4, 6]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use a list comprehension when you want to build a new list by keeping only items that match a condition.&lt;/p&gt;</description></item><item><title>How to Find an Item in a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-find-an-item-in-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-find-an-item-in-a-list-in-python/</guid><description>&lt;h1 id="how-to-find-an-item-in-a-list-in-python"&gt;How to Find an Item in a List in Python&lt;/h1&gt;
&lt;p&gt;If you want to find an item in a Python list, there are a few simple ways to do it.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Check if a list contains a value&lt;/li&gt;
&lt;li&gt;Get the index of a value&lt;/li&gt;
&lt;li&gt;Find items safely when they may not exist&lt;/li&gt;
&lt;li&gt;Understand when to use &lt;code&gt;in&lt;/code&gt; and when to use &lt;code&gt;index()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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="n"&gt;fruits&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;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;orange&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;# Check if an item exists&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;banana&amp;#34;&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fruits&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;Found it&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;# Get the index of an 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;position&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fruits&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;banana&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;position&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 1&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;in&lt;/code&gt; when you only need to check if an item exists. Use &lt;code&gt;list.index()&lt;/code&gt; when you need its position.&lt;/p&gt;</description></item><item><title>How to Format Strings in Python</title><link>https://pythonbeginner.help/how-to/how-to-format-strings-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-format-strings-in-python/</guid><description>&lt;h1 id="how-to-format-strings-in-python"&gt;How to Format Strings in Python&lt;/h1&gt;
&lt;p&gt;String formatting in Python means putting values into text.&lt;/p&gt;
&lt;p&gt;This is useful when you want to build messages, labels, filenames, or printed output. For example, you might want to combine text with variables like a name, price, or age.&lt;/p&gt;
&lt;p&gt;For most beginners, the best option is an &lt;strong&gt;f-string&lt;/strong&gt; because it is simple and easy to read.&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="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&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="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;My name is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; and I am &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; years old.&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;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>How to Get All Keys from a Dictionary in Python</title><link>https://pythonbeginner.help/how-to/how-to-get-all-keys-from-a-dictionary-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-get-all-keys-from-a-dictionary-in-python/</guid><description>&lt;h1 id="how-to-get-all-keys-from-a-dictionary-in-python"&gt;How to Get All Keys from a Dictionary in Python&lt;/h1&gt;
&lt;p&gt;If you want every key from a Python dictionary, use the &lt;code&gt;keys()&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;This is useful when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;see which keys a dictionary has&lt;/li&gt;
&lt;li&gt;loop through the keys&lt;/li&gt;
&lt;li&gt;check for a key&lt;/li&gt;
&lt;li&gt;convert the keys to a list&lt;/li&gt;
&lt;/ul&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="n"&gt;person&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 class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;city&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Lima&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="n"&gt;keys_view&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keys&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;keys_view&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="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;keys_view&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;
&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;dict_keys&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;city&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;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;city&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;Use &lt;code&gt;dict.keys()&lt;/code&gt; to get all keys. Convert it with &lt;code&gt;list()&lt;/code&gt; if you need a regular list.&lt;/p&gt;</description></item><item><title>How to Get All Values from a Dictionary in Python</title><link>https://pythonbeginner.help/how-to/how-to-get-all-values-from-a-dictionary-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-get-all-values-from-a-dictionary-in-python/</guid><description>&lt;h1 id="how-to-get-all-values-from-a-dictionary-in-python"&gt;How to Get All Values from a Dictionary in Python&lt;/h1&gt;
&lt;p&gt;If you want all values from a Python dictionary, the simplest solution is to use &lt;code&gt;dict.values()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This page shows you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to get all values from a dictionary&lt;/li&gt;
&lt;li&gt;What &lt;code&gt;dict.values()&lt;/code&gt; returns&lt;/li&gt;
&lt;li&gt;When to convert the result to a list&lt;/li&gt;
&lt;li&gt;How to loop through dictionary values&lt;/li&gt;
&lt;/ul&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="n"&gt;person&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 class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;city&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Lima&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="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&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;values&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="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&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;
&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;dict_values&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Ana&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Lima&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;Ana&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Lima&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;Use &lt;code&gt;dict.values()&lt;/code&gt; to get all dictionary values. Convert it with &lt;code&gt;list()&lt;/code&gt; if you need a regular list.&lt;/p&gt;</description></item><item><title>How to Get the Length of a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-get-the-length-of-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-get-the-length-of-a-list-in-python/</guid><description>&lt;h1 id="how-to-get-the-length-of-a-list-in-python"&gt;How to Get the Length of a List in Python&lt;/h1&gt;
&lt;p&gt;If you want to count how many items are in a Python list, use &lt;code&gt;len()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This page shows the quickest way to do that, explains what &lt;code&gt;len()&lt;/code&gt; returns, and points out common beginner mistakes. If you want a broader explanation of the function, see &lt;a href="https://pythonbeginner.help/reference/python-len-function-explained/"&gt;Python len() Function Explained&lt;/a&gt;.&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="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 class="mi"&gt;40&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;count&lt;/span&gt; &lt;span class="o"&gt;=&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;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;count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 4&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;len(list_name)&lt;/code&gt; to get the number of items in a list.&lt;/p&gt;</description></item><item><title>How to Get User Input in Python</title><link>https://pythonbeginner.help/how-to/how-to-get-user-input-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-get-user-input-in-python/</guid><description>&lt;h1 id="how-to-get-user-input-in-python"&gt;How to Get User Input in Python&lt;/h1&gt;
&lt;p&gt;If you want your Python program to ask the user for a name, age, or any other value, use &lt;code&gt;input()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ask for input with &lt;code&gt;input()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;store the result in a variable&lt;/li&gt;
&lt;li&gt;print the value back to the user&lt;/li&gt;
&lt;li&gt;convert input text to numbers when needed&lt;/li&gt;
&lt;li&gt;avoid common beginner mistakes&lt;/li&gt;
&lt;/ul&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="n"&gt;name&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 your name: &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="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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;input()&lt;/code&gt; always returns text. If you need a number, convert it with &lt;a href="https://pythonbeginner.help/reference/python-int-function-explained/"&gt;&lt;code&gt;int()&lt;/code&gt;&lt;/a&gt; or &lt;a href="https://pythonbeginner.help/reference/python-float-function-explained/"&gt;&lt;code&gt;float()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>How to Handle API Responses in Python</title><link>https://pythonbeginner.help/how-to/how-to-handle-api-responses-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-handle-api-responses-in-python/</guid><description>&lt;h1 id="how-to-handle-api-responses-in-python"&gt;How to Handle API Responses in Python&lt;/h1&gt;
&lt;p&gt;After you make a request to an API, the next step is handling the response safely.&lt;/p&gt;
&lt;p&gt;This means:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;checking whether the request succeeded&lt;/li&gt;
&lt;li&gt;reading the returned data&lt;/li&gt;
&lt;li&gt;handling JSON correctly&lt;/li&gt;
&lt;li&gt;dealing with errors like bad status codes or invalid response content&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page shows a simple beginner-friendly pattern for working with API responses in Python.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;requests&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;https://api.example.com/data&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&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="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&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;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;200&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&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&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;Request failed:&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&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;response&lt;/span&gt;&lt;span class="o"&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;Use this pattern to check whether the request worked before reading the response data.&lt;/p&gt;</description></item><item><title>How to Handle Exceptions in Python</title><link>https://pythonbeginner.help/how-to/how-to-handle-exceptions-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-handle-exceptions-in-python/</guid><description>&lt;h1 id="how-to-handle-exceptions-in-python"&gt;How to Handle Exceptions in Python&lt;/h1&gt;
&lt;p&gt;Learn how to catch and respond to errors in Python so your program does not crash unexpectedly. This page focuses on practical exception handling patterns beginners can use right away.&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;p&gt;Use &lt;code&gt;try&lt;/code&gt; and &lt;code&gt;except&lt;/code&gt; when code might fail because of bad input, missing files, or other runtime problems.&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;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="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&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="mi"&gt;10&lt;/span&gt; &lt;span class="o"&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 whole number.&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;ZeroDivisionError&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 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;figure class="diagram" role="group" aria-label="A matching except handler runs instead of the program crashing."&gt;
&lt;svg width="716" height="166" viewBox="0 0 716 166" class="d-svg" xmlns="http://www.w3.org/2000/svg" role="img"&gt;
 &lt;defs&gt;&lt;marker id="flowarrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"&gt;&lt;path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/&gt;&lt;/marker&gt;&lt;/defs&gt;&lt;rect x="208" y="8" width="305" height="44" rx="8" class="d-node-try"/&gt;
 &lt;text x="360" y="30" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;try: int(input(...)) then 10 / number&lt;/text&gt;&lt;path d="M208 30 H172 V110" class="d-edge" marker-end="url(#flowarrow)" fill="none"/&gt;
 &lt;text x="250" y="72" class="d-edge-label d-edge-ok"&gt;no error&lt;/text&gt;
 &lt;path d="M512 30 H547 V110" class="d-edge" marker-end="url(#flowarrow)" fill="none"/&gt;
 &lt;text x="430" y="72" class="d-edge-label d-edge-err"&gt;error raised&lt;/text&gt;&lt;rect x="20" y="110" width="305" height="44" rx="8" class="d-node"/&gt;
 &lt;text x="172" y="132" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;continue&lt;/text&gt;&lt;rect x="395" y="110" width="305" height="44" rx="8" class="d-node-err"/&gt;
 &lt;text x="547" y="132" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;except: show a helpful message&lt;/text&gt;&lt;/svg&gt;&lt;figcaption&gt;A matching except handler runs instead of the program crashing.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;In this example:&lt;/p&gt;</description></item><item><title>How to Import a Module in Python</title><link>https://pythonbeginner.help/how-to/how-to-import-a-module-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-import-a-module-in-python/</guid><description>&lt;h1 id="how-to-import-a-module-in-python"&gt;How to Import a Module in Python&lt;/h1&gt;
&lt;p&gt;Importing a module lets you use code that already exists instead of writing everything yourself.&lt;/p&gt;
&lt;p&gt;In Python, modules can be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;built-in modules that come with Python&lt;/li&gt;
&lt;li&gt;installed packages from outside Python&lt;/li&gt;
&lt;li&gt;your own &lt;code&gt;.py&lt;/code&gt; files&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This guide shows you how to import modules, use functions from them, and avoid common beginner mistakes.&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="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="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;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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;random&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;randint&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;randint&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;10&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;import module_name&lt;/code&gt; to load a module.&lt;/p&gt;</description></item><item><title>How to Inherit from a Class in Python</title><link>https://pythonbeginner.help/how-to/how-to-inherit-from-a-class-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-inherit-from-a-class-in-python/</guid><description>&lt;h1 id="how-to-inherit-from-a-class-in-python"&gt;How to Inherit from a Class in Python&lt;/h1&gt;
&lt;p&gt;Inheritance lets you create a new class from an existing class.&lt;/p&gt;
&lt;p&gt;This is useful when two classes should share code. The new class can reuse methods and attributes from the existing class, and it can also add new behavior or replace old behavior when needed.&lt;/p&gt;
&lt;p&gt;If you are new to classes, it may help to first read &lt;a href="https://pythonbeginner.help/how-to/how-to-create-a-class-in-python/"&gt;how to create a class in Python&lt;/a&gt; and &lt;a href="https://pythonbeginner.help/learn/python-classes-and-objects-explained"&gt;Python classes and objects explained&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>How to Install a Python Package with pip</title><link>https://pythonbeginner.help/how-to/how-to-install-a-python-package-with-pip/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-install-a-python-package-with-pip/</guid><description>&lt;h1 id="how-to-install-a-python-package-with-pip"&gt;How to Install a Python Package with pip&lt;/h1&gt;
&lt;p&gt;Learn how to install Python packages with pip, check that pip works, and fix the most common installation problems. This page focuses on the basic command-line steps beginners need.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Quick command&lt;/strong&gt;&lt;/p&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;Use &lt;code&gt;python -m pip&lt;/code&gt; if &lt;code&gt;pip&lt;/code&gt; does not work by itself. Replace &lt;code&gt;requests&lt;/code&gt; with the package name you want to install.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="what-this-page-helps-you-do"&gt;What this page helps you do &lt;a class="heading-anchor" href="#what-this-page-helps-you-do" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;</description></item><item><title>How to Install Python on Windows, macOS, and Linux</title><link>https://pythonbeginner.help/learn/how-to-install-python-on-windows-macos-and-linux/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/how-to-install-python-on-windows-macos-and-linux/</guid><description>&lt;h1 id="how-to-install-python-on-windows-macos-and-linux"&gt;How to Install Python on Windows, macOS, and Linux&lt;/h1&gt;
&lt;p&gt;Installing Python is one of the first steps in learning the language. This guide shows you how to install Python 3 on Windows, macOS, and Linux, how to check whether it is already installed, and how to verify that it works correctly.&lt;/p&gt;
&lt;p&gt;The goal is simple: get one working Python 3 installation that you can run from the command line without confusion.&lt;/p&gt;</description></item><item><title>How to Join Strings in Python</title><link>https://pythonbeginner.help/how-to/how-to-join-strings-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-join-strings-in-python/</guid><description>&lt;h1 id="how-to-join-strings-in-python"&gt;How to Join Strings in Python&lt;/h1&gt;
&lt;p&gt;If you want to combine text in Python, there are a few simple ways to do it.&lt;/p&gt;
&lt;p&gt;On this page, you will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to join two or more strings into one string&lt;/li&gt;
&lt;li&gt;How to add separators like spaces, commas, or dashes&lt;/li&gt;
&lt;li&gt;When to use &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;str.join()&lt;/code&gt;, or f-strings&lt;/li&gt;
&lt;li&gt;How to avoid common string joining errors&lt;/li&gt;
&lt;/ul&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="n"&gt;words&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;Python&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;is&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;fun&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="n"&gt;words&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>How to List Files in a Directory in Python</title><link>https://pythonbeginner.help/how-to/how-to-list-files-in-a-directory-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-list-files-in-a-directory-in-python/</guid><description>&lt;h1 id="how-to-list-files-in-a-directory-in-python"&gt;How to List Files in a Directory in Python&lt;/h1&gt;
&lt;p&gt;If you want to list files in a folder in Python, there are two common beginner-friendly options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;os.listdir()&lt;/code&gt; for a simple list of names&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pathlib&lt;/code&gt; for cleaner path handling&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page shows how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;List everything inside a directory&lt;/li&gt;
&lt;li&gt;Show only files, not subdirectories&lt;/li&gt;
&lt;li&gt;Print file names or full file paths&lt;/li&gt;
&lt;li&gt;Use beginner-friendly methods first&lt;/li&gt;
&lt;/ul&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="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&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;folder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Path&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 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;folder&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iterdir&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;item&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_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="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="o"&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This prints file names in the current directory and skips subdirectories.&lt;/p&gt;</description></item><item><title>How to Loop Through a Dictionary in Python</title><link>https://pythonbeginner.help/how-to/how-to-loop-through-a-dictionary-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-loop-through-a-dictionary-in-python/</guid><description>&lt;h1 id="how-to-loop-through-a-dictionary-in-python"&gt;How to Loop Through a Dictionary in Python&lt;/h1&gt;
&lt;p&gt;If you want to go through the contents of a dictionary in Python, there are three main patterns to know:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;loop through &lt;strong&gt;keys&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;loop through &lt;strong&gt;values&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;loop through &lt;strong&gt;keys and values together&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page shows the most useful ways to do that with simple examples.&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="n"&gt;student&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 class="s2"&gt;&amp;#34;age&amp;#34;&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="s2"&gt;&amp;#34;city&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Lima&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;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&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;key&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;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="n"&gt;name&lt;/span&gt; &lt;span class="n"&gt;Ana&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="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="n"&gt;city&lt;/span&gt; &lt;span class="n"&gt;Lima&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;.items()&lt;/code&gt; when you need both the key and the value during the loop.&lt;/p&gt;</description></item><item><title>How to Loop Through a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-loop-through-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-loop-through-a-list-in-python/</guid><description>&lt;h1 id="how-to-loop-through-a-list-in-python"&gt;How to Loop Through a List in Python&lt;/h1&gt;
&lt;p&gt;If you want to work with every item in a Python list, you usually use a loop.&lt;/p&gt;
&lt;p&gt;This page shows the main ways to loop through a list in Python:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read each item one by one&lt;/li&gt;
&lt;li&gt;Print or use each value&lt;/li&gt;
&lt;li&gt;Get both the index and the value&lt;/li&gt;
&lt;li&gt;Choose the simplest loop for your task&lt;/li&gt;
&lt;/ul&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="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;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;cherry&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="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;Output:&lt;/p&gt;</description></item><item><title>How to Make an API Request in Python</title><link>https://pythonbeginner.help/how-to/how-to-make-an-api-request-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-make-an-api-request-in-python/</guid><description>&lt;h1 id="how-to-make-an-api-request-in-python"&gt;How to Make an API Request in Python&lt;/h1&gt;
&lt;p&gt;If you want to get data from a website or service in Python, a common first step is making an API request.&lt;/p&gt;
&lt;p&gt;This page shows the simplest way to send a basic &lt;strong&gt;GET request&lt;/strong&gt; in Python, check whether it worked, and read JSON data safely. It stays focused on one task so you can get a working example quickly.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use this when you want the fastest working example.&lt;/p&gt;</description></item><item><title>How to Merge Dictionaries in Python</title><link>https://pythonbeginner.help/how-to/how-to-merge-dictionaries-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-merge-dictionaries-in-python/</guid><description>&lt;h1 id="how-to-merge-dictionaries-in-python"&gt;How to Merge Dictionaries in Python&lt;/h1&gt;
&lt;p&gt;Merging dictionaries in Python means combining key-value pairs from two or more dictionaries into one.&lt;/p&gt;
&lt;p&gt;This page shows the main ways to do that, including what happens when the same key appears in more than one dictionary. It also helps you choose the right method for your Python version and avoid changing a dictionary by mistake.&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="n"&gt;dict1&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 class="s2"&gt;&amp;#34;age&amp;#34;&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;dict2&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;city&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Lima&amp;#34;&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;21&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;merged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dict1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;dict2&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;merged&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="c1"&gt;# {&amp;#39;name&amp;#39;: &amp;#39;Ana&amp;#39;, &amp;#39;age&amp;#39;: 21, &amp;#39;city&amp;#39;: &amp;#39;Lima&amp;#39;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In Python 3.9+, the &lt;code&gt;|&lt;/code&gt; operator merges dictionaries.&lt;/p&gt;</description></item><item><title>How to Merge Two Lists in Python</title><link>https://pythonbeginner.help/how-to/how-to-merge-two-lists-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-merge-two-lists-in-python/</guid><description>&lt;h1 id="how-to-merge-two-lists-in-python"&gt;How to Merge Two Lists in Python&lt;/h1&gt;
&lt;p&gt;If you want to combine two Python lists into one list, there are a few simple ways to do it.&lt;/p&gt;
&lt;p&gt;On this page, you will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to combine two lists into one list&lt;/li&gt;
&lt;li&gt;When to create a new list and when to change an existing list&lt;/li&gt;
&lt;li&gt;How to avoid common beginner mistakes when merging lists&lt;/li&gt;
&lt;/ul&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="n"&gt;list1&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="n"&gt;list2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&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 class="mi"&gt;6&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;merged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;list2&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;merged&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>How to Parse JSON in Python</title><link>https://pythonbeginner.help/how-to/how-to-parse-json-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-parse-json-in-python/</guid><description>&lt;h1 id="how-to-parse-json-in-python"&gt;How to Parse JSON in Python&lt;/h1&gt;
&lt;p&gt;If you have JSON text and want to use it in Python, the usual goal is to turn that text into normal Python data such as dictionaries and lists.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Parse JSON text into Python objects&lt;/li&gt;
&lt;li&gt;Understand what type Python gives you back&lt;/li&gt;
&lt;li&gt;Read values from parsed JSON safely&lt;/li&gt;
&lt;li&gt;Choose between &lt;code&gt;json.loads()&lt;/code&gt; and &lt;code&gt;json.load()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&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;json_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;{&amp;#34;name&amp;#34;: &amp;#34;Ana&amp;#34;, &amp;#34;age&amp;#34;: 25, &amp;#34;is_admin&amp;#34;: false}&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&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="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_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="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&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;name&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;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;/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>How to Pretty Print JSON in Python</title><link>https://pythonbeginner.help/how-to/how-to-pretty-print-json-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-pretty-print-json-in-python/</guid><description>&lt;h1 id="how-to-pretty-print-json-in-python"&gt;How to Pretty Print JSON in Python&lt;/h1&gt;
&lt;p&gt;Pretty printing JSON means formatting it with indentation and line breaks so it is easier to read.&lt;/p&gt;
&lt;p&gt;This is useful when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;inspect API data&lt;/li&gt;
&lt;li&gt;read nested objects in the terminal&lt;/li&gt;
&lt;li&gt;save cleaner JSON files&lt;/li&gt;
&lt;li&gt;debug your program&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In Python, the most common way to pretty print JSON is with the &lt;code&gt;json&lt;/code&gt; 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;json&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;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 class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;skills&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Python&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;SQL&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&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="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&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;json.dumps(..., indent=4)&lt;/code&gt; to print JSON with readable spacing and line breaks.&lt;/p&gt;</description></item><item><title>How to Raise an Exception in Python</title><link>https://pythonbeginner.help/how-to/how-to-raise-an-exception-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-raise-an-exception-in-python/</guid><description>&lt;h1 id="how-to-raise-an-exception-in-python"&gt;How to Raise an Exception in Python&lt;/h1&gt;
&lt;p&gt;Use the &lt;code&gt;raise&lt;/code&gt; statement when you want your program to stop and show a clear error on purpose.&lt;/p&gt;
&lt;p&gt;This is useful when your code detects invalid data, a missing value, or a rule that should not be broken. On this page, you will learn when to raise an exception, how to choose an exception type, and how to write a helpful error message.&lt;/p&gt;</description></item><item><title>How to Read a CSV File in Python</title><link>https://pythonbeginner.help/how-to/how-to-read-a-csv-file-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-read-a-csv-file-in-python/</guid><description>&lt;h1 id="how-to-read-a-csv-file-in-python"&gt;How to Read a CSV File in Python&lt;/h1&gt;
&lt;p&gt;If you want to read a CSV file in Python, the simplest and most reliable way is to use the built-in &lt;code&gt;csv&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read rows from a CSV file in Python&lt;/li&gt;
&lt;li&gt;Understand why the &lt;code&gt;csv&lt;/code&gt; module is better than &lt;code&gt;split(',')&lt;/code&gt; for real CSV data&lt;/li&gt;
&lt;li&gt;Loop through rows safely&lt;/li&gt;
&lt;li&gt;Read CSV files with or without headers&lt;/li&gt;
&lt;/ul&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="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;csv&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="s1"&gt;&amp;#39;data.csv&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newline&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;#39;&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="s1"&gt;&amp;#39;utf-8&amp;#39;&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;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;(&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;reader&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;row&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;csv.reader()&lt;/code&gt; for basic CSV files. &lt;code&gt;newline=''&lt;/code&gt; helps the &lt;code&gt;csv&lt;/code&gt; module read rows correctly.&lt;/p&gt;</description></item><item><title>How to Read a File in Python</title><link>https://pythonbeginner.help/how-to/how-to-read-a-file-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-read-a-file-in-python/</guid><description>&lt;h1 id="how-to-read-a-file-in-python"&gt;How to Read a File in Python&lt;/h1&gt;
&lt;p&gt;Learn the simplest ways to open and read a file in Python. This page focuses on reading text files safely, understanding what each method returns, and avoiding common beginner mistakes.&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;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;example.txt&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;r&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;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&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;with open(...)&lt;/code&gt; so Python closes the file automatically after reading.&lt;/p&gt;
&lt;h2 id="what-this-page-helps-you-do"&gt;What this page helps you do &lt;a class="heading-anchor" href="#what-this-page-helps-you-do" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Open a text file&lt;/li&gt;
&lt;li&gt;Read the whole file at once&lt;/li&gt;
&lt;li&gt;Read one line at a time&lt;/li&gt;
&lt;li&gt;Choose the right reading method&lt;/li&gt;
&lt;li&gt;Avoid common file-reading errors&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="the-simplest-way-to-read-a-file"&gt;The simplest way to read a file &lt;a class="heading-anchor" href="#the-simplest-way-to-read-a-file" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The most common way to read a text file in Python is:&lt;/p&gt;</description></item><item><title>How to Read a File Line by Line in Python</title><link>https://pythonbeginner.help/how-to/how-to-read-a-file-line-by-line-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-read-a-file-line-by-line-in-python/</guid><description>&lt;h1 id="how-to-read-a-file-line-by-line-in-python"&gt;How to Read a File Line by Line in Python&lt;/h1&gt;
&lt;p&gt;If you want to process a text file one line at a time, Python gives you a simple and memory-friendly way to do it.&lt;/p&gt;
&lt;p&gt;This is useful when working with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;text files&lt;/li&gt;
&lt;li&gt;log files&lt;/li&gt;
&lt;li&gt;plain text data&lt;/li&gt;
&lt;li&gt;large files you do not want to load fully into memory&lt;/li&gt;
&lt;/ul&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;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;example.txt&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;r&amp;#39;&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="ow"&gt;in&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use a &lt;code&gt;for&lt;/code&gt; loop with &lt;code&gt;open()&lt;/code&gt; to read one line at a time.&lt;br&gt;
&lt;code&gt;strip()&lt;/code&gt; removes the newline at the end of each line.&lt;/p&gt;</description></item><item><title>How to Remove a Key from a Dictionary in Python</title><link>https://pythonbeginner.help/how-to/how-to-remove-a-key-from-a-dictionary-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-remove-a-key-from-a-dictionary-in-python/</guid><description>&lt;h1 id="how-to-remove-a-key-from-a-dictionary-in-python"&gt;How to Remove a Key from a Dictionary in Python&lt;/h1&gt;
&lt;p&gt;If you want to remove a key from a Python dictionary, the main tools are &lt;code&gt;del&lt;/code&gt; and &lt;code&gt;pop()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This page shows you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to remove one key from a dictionary&lt;/li&gt;
&lt;li&gt;When to use &lt;code&gt;del&lt;/code&gt; and when to use &lt;code&gt;pop()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;How to avoid &lt;code&gt;KeyError&lt;/code&gt; if the key may not exist&lt;/li&gt;
&lt;li&gt;What happens to the removed value&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are new to dictionaries, see &lt;a href="https://pythonbeginner.help/learn/python-dictionaries-explained/"&gt;Python dictionaries explained&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>How to Remove an Item from a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-remove-an-item-from-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-remove-an-item-from-a-list-in-python/</guid><description>&lt;h1 id="how-to-remove-an-item-from-a-list-in-python"&gt;How to Remove an Item from a List in Python&lt;/h1&gt;
&lt;p&gt;If you want to remove an item from a Python list, the best method depends on what you know:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the &lt;strong&gt;value&lt;/strong&gt; of the item&lt;/li&gt;
&lt;li&gt;the &lt;strong&gt;position&lt;/strong&gt; of the item&lt;/li&gt;
&lt;li&gt;whether you want to remove &lt;strong&gt;one match&lt;/strong&gt; or &lt;strong&gt;all matches&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On this page, you will learn the main ways to delete items from a list and how to avoid common mistakes.&lt;/p&gt;</description></item><item><title>How to Remove Duplicates from a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-remove-duplicates-from-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-remove-duplicates-from-a-list-in-python/</guid><description>&lt;h1 id="how-to-remove-duplicates-from-a-list-in-python"&gt;How to Remove Duplicates from a List in Python&lt;/h1&gt;
&lt;p&gt;Removing duplicates from a list means keeping only one copy of each value.&lt;/p&gt;
&lt;p&gt;In Python, there are a few simple ways to do this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;dict.fromkeys()&lt;/code&gt; to remove duplicates &lt;strong&gt;and keep the original order&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;set()&lt;/code&gt; if you only care about unique values&lt;/li&gt;
&lt;li&gt;Use a loop if you want to understand the logic or need more control&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For most beginners, &lt;code&gt;dict.fromkeys()&lt;/code&gt; is a good default choice.&lt;/p&gt;</description></item><item><title>How to Remove Whitespace from a String in Python</title><link>https://pythonbeginner.help/how-to/how-to-remove-whitespace-from-a-string-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-remove-whitespace-from-a-string-in-python/</guid><description>&lt;h1 id="how-to-remove-whitespace-from-a-string-in-python"&gt;How to Remove Whitespace from a String in Python&lt;/h1&gt;
&lt;p&gt;If you need to clean up text in Python, there are a few common ways to remove whitespace from a string.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Remove spaces at the beginning and end&lt;/li&gt;
&lt;li&gt;Remove all normal spaces&lt;/li&gt;
&lt;li&gt;Remove tabs and newline characters too&lt;/li&gt;
&lt;li&gt;Choose the right method for the result you want&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;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34; hello world &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;text&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 class="c1"&gt;# hello world&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;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 class="c1"&gt;# helloworld&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 whitespace at the start and end.&lt;/p&gt;</description></item><item><title>How to Rename a File in Python</title><link>https://pythonbeginner.help/how-to/how-to-rename-a-file-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-rename-a-file-in-python/</guid><description>&lt;h1 id="how-to-rename-a-file-in-python"&gt;How to Rename a File in Python&lt;/h1&gt;
&lt;p&gt;If you want to rename a file in Python, the simplest built-in option is &lt;code&gt;os.rename()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Rename one existing file&lt;/li&gt;
&lt;li&gt;Use Python’s built-in &lt;code&gt;os.rename()&lt;/code&gt; function&lt;/li&gt;
&lt;li&gt;Understand what the old path and new path mean&lt;/li&gt;
&lt;li&gt;Avoid common path and file existence mistakes&lt;/li&gt;
&lt;/ul&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="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;old_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;old_file.txt&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;new_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;new_file.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="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rename&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;old_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_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;File renamed&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 works when the file exists and both paths are correct.&lt;/p&gt;</description></item><item><title>How to Replace Text in a String in Python</title><link>https://pythonbeginner.help/how-to/how-to-replace-text-in-a-string-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-replace-text-in-a-string-in-python/</guid><description>&lt;h1 id="how-to-replace-text-in-a-string-in-python"&gt;How to Replace Text in a String in Python&lt;/h1&gt;
&lt;p&gt;If you want to change part of a string in Python, the simplest tool is &lt;code&gt;str.replace()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It works well for common tasks like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;changing one word to another&lt;/li&gt;
&lt;li&gt;removing part of a string&lt;/li&gt;
&lt;li&gt;replacing all matches&lt;/li&gt;
&lt;li&gt;replacing only the first few matches&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For most beginner cases, this is the right method to use.&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="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Hello world&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;new_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;world&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Python&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;new_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;Output:&lt;/p&gt;</description></item><item><title>How to Return Multiple Values from a Function in Python</title><link>https://pythonbeginner.help/how-to/how-to-return-multiple-values-from-a-function-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-return-multiple-values-from-a-function-in-python/</guid><description>&lt;h1 id="how-to-return-multiple-values-from-a-function-in-python"&gt;How to Return Multiple Values from a Function in Python&lt;/h1&gt;
&lt;p&gt;If you want one Python function to give back more than one result, the most common solution is simple: return the values separated by commas.&lt;/p&gt;
&lt;p&gt;In practice, Python usually packs those values into a tuple. You can then unpack that tuple into separate variables.&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;def&lt;/span&gt; &lt;span class="nf"&gt;get_name_and_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 class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Alice&amp;#34;&lt;/span&gt;&lt;span class="p"&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&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_name_and_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="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 class="nb"&gt;print&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;/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="n"&gt;Alice&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="mi"&gt;25&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In Python, returning multiple values usually means returning a tuple. You can unpack the result into separate variables.&lt;/p&gt;</description></item><item><title>How to Reverse a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-reverse-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-reverse-a-list-in-python/</guid><description>&lt;h1 id="how-to-reverse-a-list-in-python"&gt;How to Reverse a List in Python&lt;/h1&gt;
&lt;p&gt;If you want to reverse a list in Python, there are a few simple ways to do it.&lt;/p&gt;
&lt;p&gt;The main choice is this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Do you want to &lt;strong&gt;change the original list&lt;/strong&gt;?&lt;/li&gt;
&lt;li&gt;Or do you want to &lt;strong&gt;make a new reversed copy&lt;/strong&gt;?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page shows the easiest beginner-friendly methods and explains the difference between &lt;code&gt;reverse()&lt;/code&gt;, slicing, and &lt;code&gt;reversed()&lt;/code&gt;.&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="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 class="mi"&gt;4&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;# Change the original list&lt;/span&gt;
&lt;/span&gt;&lt;/span&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="n"&gt;reverse&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&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 make a reversed copy&lt;/span&gt;
&lt;/span&gt;&lt;/span&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 class="mi"&gt;4&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;reversed_numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[::&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 class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reversed_numbers&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;list.reverse()&lt;/code&gt; to reverse the same list. Use slicing &lt;code&gt;[::-1]&lt;/code&gt; if you want a new reversed list.&lt;/p&gt;</description></item><item><title>How to Run Python Code (Command Line and IDEs)</title><link>https://pythonbeginner.help/learn/how-to-run-python-code-command-line-and-ides/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/how-to-run-python-code-command-line-and-ides/</guid><description>&lt;h1 id="how-to-run-python-code-command-line-and-ides"&gt;How to Run Python Code (Command Line and IDEs)&lt;/h1&gt;
&lt;p&gt;If you are new to Python, one of the first things to learn is &lt;strong&gt;how to actually run your code&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Run Python in the terminal for quick tests&lt;/li&gt;
&lt;li&gt;Run a saved &lt;code&gt;.py&lt;/code&gt; file from the command line&lt;/li&gt;
&lt;li&gt;Run Python code in common IDEs and editors&lt;/li&gt;
&lt;li&gt;Understand when to use interactive mode and when to use script files&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you just want the fastest possible test, try this first:&lt;/p&gt;</description></item><item><title>How to Send a POST Request in Python</title><link>https://pythonbeginner.help/how-to/how-to-send-a-post-request-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-send-a-post-request-in-python/</guid><description>&lt;h1 id="how-to-send-a-post-request-in-python"&gt;How to Send a POST Request in Python&lt;/h1&gt;
&lt;p&gt;If you want to send data to an API in Python, a POST request is one of the most common ways to do it.&lt;/p&gt;
&lt;p&gt;On this page, you will learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Send a basic POST request in Python&lt;/li&gt;
&lt;li&gt;Send JSON data to an API&lt;/li&gt;
&lt;li&gt;Check the status code&lt;/li&gt;
&lt;li&gt;Read JSON or text responses&lt;/li&gt;
&lt;li&gt;Avoid common beginner mistakes&lt;/li&gt;
&lt;/ul&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="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;requests&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;https://httpbin.org/post&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;payload&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;Alice&amp;#34;&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;25&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&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;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&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;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&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;requests.post()&lt;/code&gt; with &lt;code&gt;json=&lt;/code&gt; when the API expects JSON data.&lt;/p&gt;</description></item><item><title>How to Sort a List in Python</title><link>https://pythonbeginner.help/how-to/how-to-sort-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-sort-a-list-in-python/</guid><description>&lt;h1 id="how-to-sort-a-list-in-python"&gt;How to Sort a List in Python&lt;/h1&gt;
&lt;p&gt;Sorting a list is a common Python task. On this page, you will learn the simplest ways to sort a list in ascending order, descending order, and how to decide whether to change the original list or create a new sorted one.&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="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;5&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;9&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 class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sort&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="c1"&gt;# [1, 2, 5, 9]&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="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;cherry&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="nb"&gt;sorted&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 class="c1"&gt;# [&amp;#39;apple&amp;#39;, &amp;#39;banana&amp;#39;, &amp;#39;cherry&amp;#39;]&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;list.sort()&lt;/code&gt; to change the original list. Use &lt;code&gt;sorted()&lt;/code&gt; to return a new sorted list.&lt;/p&gt;</description></item><item><title>How to Sort a List of Dictionaries in Python</title><link>https://pythonbeginner.help/how-to/how-to-sort-a-list-of-dictionaries-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-sort-a-list-of-dictionaries-in-python/</guid><description>&lt;h1 id="how-to-sort-a-list-of-dictionaries-in-python"&gt;How to Sort a List of Dictionaries in Python&lt;/h1&gt;
&lt;p&gt;If you have a list where each item is a dictionary, you can sort it by one dictionary key such as &lt;code&gt;age&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;price&lt;/code&gt;, or &lt;code&gt;city&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is common when working with real data from JSON files, APIs, or form input.&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="n"&gt;people&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 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 class="s2"&gt;&amp;#34;age&amp;#34;&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="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;Ben&amp;#34;&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;22&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="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;Cara&amp;#34;&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;27&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&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;sorted_people&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;person&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;sorted_people&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;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Ben&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Cara&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Ana&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&amp;#39;&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;a href="https://pythonbeginner.help/reference/python-sorted-function-explained"&gt;&lt;code&gt;sorted()&lt;/code&gt;&lt;/a&gt; when you want a new sorted list. Use a &lt;code&gt;key&lt;/code&gt; function to choose which dictionary value to sort by.&lt;/p&gt;</description></item><item><title>How to Split a String in Python</title><link>https://pythonbeginner.help/how-to/how-to-split-a-string-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-split-a-string-in-python/</guid><description>&lt;h1 id="how-to-split-a-string-in-python"&gt;How to Split a String in Python&lt;/h1&gt;
&lt;p&gt;If you want to break text into smaller pieces in Python, use string splitting methods.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Split a string into a list&lt;/li&gt;
&lt;li&gt;Choose the right separator&lt;/li&gt;
&lt;li&gt;Work with spaces, commas, and line breaks&lt;/li&gt;
&lt;li&gt;Understand what &lt;code&gt;split()&lt;/code&gt; returns&lt;/li&gt;
&lt;/ul&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="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;apple,banana,cherry&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&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;/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;cherry&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;Use &lt;code&gt;split()&lt;/code&gt; to turn one string into a list of smaller strings.&lt;/p&gt;</description></item><item><title>How to Use Command Line Arguments in Python</title><link>https://pythonbeginner.help/how-to/how-to-use-command-line-arguments-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-use-command-line-arguments-in-python/</guid><description>&lt;h1 id="how-to-use-command-line-arguments-in-python"&gt;How to Use Command Line Arguments in Python&lt;/h1&gt;
&lt;p&gt;Command line arguments let you pass values to a Python script when you run it in a terminal.&lt;/p&gt;
&lt;p&gt;This is useful when you want the same script to work with different inputs, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a file name&lt;/li&gt;
&lt;li&gt;a number&lt;/li&gt;
&lt;li&gt;a short text value&lt;/li&gt;
&lt;li&gt;a simple command&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this guide, you will learn how to pass arguments to a script, read them with &lt;code&gt;sys.argv&lt;/code&gt;, and handle missing input safely.&lt;/p&gt;</description></item><item><title>How to Use Default Arguments in Python</title><link>https://pythonbeginner.help/how-to/how-to-use-default-arguments-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-use-default-arguments-in-python/</guid><description>&lt;h1 id="how-to-use-default-arguments-in-python"&gt;How to Use Default Arguments in Python&lt;/h1&gt;
&lt;p&gt;Default arguments let you give a function parameter a starting value in the function definition.&lt;/p&gt;
&lt;p&gt;This means a function can work in two ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;with the argument you pass in&lt;/li&gt;
&lt;li&gt;or with a built-in fallback value&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is useful when one value is common, but you still want the option to change it.&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;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 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 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;message&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&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="s2"&gt;&amp;#34;Hi&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;Output:&lt;/p&gt;</description></item><item><title>How to Use enumerate() in Python</title><link>https://pythonbeginner.help/how-to/how-to-use-enumerate-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-use-enumerate-in-python/</guid><description>&lt;h1 id="how-to-use-enumerate-in-python"&gt;How to Use &lt;code&gt;enumerate()&lt;/code&gt; in Python&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;enumerate()&lt;/code&gt; helps you loop over items and get both the index and the value at the same time.&lt;/p&gt;
&lt;p&gt;This is useful when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;print numbered items&lt;/li&gt;
&lt;li&gt;track where something appears in a list&lt;/li&gt;
&lt;li&gt;build simple menus&lt;/li&gt;
&lt;li&gt;avoid managing a separate counter variable&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are still getting comfortable with loops, this function can make your code cleaner and easier to read. If you need a refresher first, see &lt;a href="https://pythonbeginner.help/learn/python-for-loops-explained"&gt;Python for loops explained&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>How to Use List Comprehensions in Python</title><link>https://pythonbeginner.help/how-to/how-to-use-list-comprehensions-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-use-list-comprehensions-in-python/</guid><description>&lt;h1 id="how-to-use-list-comprehensions-in-python"&gt;How to Use List Comprehensions in Python&lt;/h1&gt;
&lt;p&gt;List comprehensions give you a short way to build a new list from existing data.&lt;/p&gt;
&lt;p&gt;They are useful when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;transform values&lt;/li&gt;
&lt;li&gt;filter items&lt;/li&gt;
&lt;li&gt;replace a simple &lt;code&gt;for&lt;/code&gt; loop with a shorter pattern&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you already know basic &lt;code&gt;for&lt;/code&gt; loops, list comprehensions are a good next step.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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 class="mi"&gt;4&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;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;squares&lt;/span&gt; &lt;span class="o"&gt;=&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="n"&gt;n&lt;/span&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;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;squares&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;# Output:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# [1, 4, 9, 16, 25]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use a list comprehension when you want to build a new list from another iterable in one clear line.&lt;/p&gt;</description></item><item><title>How to Use try-except Blocks in Python</title><link>https://pythonbeginner.help/how-to/how-to-use-try-except-blocks-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-use-try-except-blocks-in-python/</guid><description>&lt;h1 id="how-to-use-try-except-blocks-in-python"&gt;How to Use try-except Blocks in Python&lt;/h1&gt;
&lt;p&gt;Learn how to catch errors in Python with &lt;code&gt;try-except&lt;/code&gt; blocks so your program does not stop unexpectedly. This page focuses on the basic pattern, when to use it, and beginner-friendly examples.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="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&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="mi"&gt;10&lt;/span&gt; &lt;span class="o"&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 whole number.&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;ZeroDivisionError&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 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;Use &lt;code&gt;try&lt;/code&gt; for code that may fail, and &lt;code&gt;except&lt;/code&gt; for the specific errors you want to handle.&lt;/p&gt;</description></item><item><title>How to Use zip() in Python</title><link>https://pythonbeginner.help/how-to/how-to-use-zip-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-use-zip-in-python/</guid><description>&lt;h1 id="how-to-use-zip-in-python"&gt;How to Use &lt;code&gt;zip()&lt;/code&gt; in Python&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;zip()&lt;/code&gt; lets you combine items from two or more iterables by their position.&lt;/p&gt;
&lt;p&gt;It is useful when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;loop through two lists at the same time&lt;/li&gt;
&lt;li&gt;create pairs of related values&lt;/li&gt;
&lt;li&gt;turn two lists into a dictionary&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For beginners, the most common use is looping through related data like names and scores.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;names&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;Ana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Ben&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Cara&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;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;85&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;88&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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scores&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&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>How to Write a CSV File in Python</title><link>https://pythonbeginner.help/how-to/how-to-write-a-csv-file-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-write-a-csv-file-in-python/</guid><description>&lt;h1 id="how-to-write-a-csv-file-in-python"&gt;How to Write a CSV File in Python&lt;/h1&gt;
&lt;p&gt;If you want to save table-like data in Python, a CSV file is a common choice.&lt;/p&gt;
&lt;p&gt;A CSV file stores data in rows and columns. Python includes a built-in &lt;code&gt;csv&lt;/code&gt; module that makes writing CSV files much easier and safer than building the text yourself.&lt;/p&gt;
&lt;p&gt;This page shows you how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a new CSV file in Python&lt;/li&gt;
&lt;li&gt;Write one row or many rows&lt;/li&gt;
&lt;li&gt;Use the built-in &lt;code&gt;csv&lt;/code&gt; module&lt;/li&gt;
&lt;li&gt;Understand when to use &lt;code&gt;csv.writer()&lt;/code&gt; and &lt;code&gt;csv.DictWriter()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&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="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;csv&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;rows&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 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;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;city&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="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Alice&amp;#34;&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 class="s2"&gt;&amp;#34;London&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="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Bob&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Paris&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="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;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;people.csv&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;newline&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="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;writer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;writer&lt;/span&gt;&lt;span class="p"&gt;(&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;writer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;writerows&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&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;newline=&amp;quot;&amp;quot;&lt;/code&gt; when opening the file. This helps prevent extra blank lines in CSV output.&lt;/p&gt;</description></item><item><title>How to Write to a File in Python</title><link>https://pythonbeginner.help/how-to/how-to-write-to-a-file-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/how-to/how-to-write-to-a-file-in-python/</guid><description>&lt;h1 id="how-to-write-to-a-file-in-python"&gt;How to Write to a File in Python&lt;/h1&gt;
&lt;p&gt;If you want to save text from your Python program into a file, use the built-in &lt;code&gt;open()&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;This page shows the simplest way to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;write text to a file&lt;/li&gt;
&lt;li&gt;create a file if it does not exist&lt;/li&gt;
&lt;li&gt;choose the right file mode&lt;/li&gt;
&lt;li&gt;avoid overwriting a file by mistake&lt;/li&gt;
&lt;/ul&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;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;notes.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="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="s2"&gt;&amp;#34;Hello, world!&lt;/span&gt;&lt;span class="se"&gt;\n&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;This creates &lt;code&gt;notes.txt&lt;/code&gt; if it does not exist.&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>Instance vs Class Variables in Python</title><link>https://pythonbeginner.help/learn/instance-vs-class-variables-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/instance-vs-class-variables-in-python/</guid><description>&lt;h1 id="instance-vs-class-variables-in-python"&gt;Instance vs Class Variables in Python&lt;/h1&gt;
&lt;p&gt;In Python classes, &lt;strong&gt;instance variables&lt;/strong&gt; and &lt;strong&gt;class variables&lt;/strong&gt; are used for different kinds of data.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use an &lt;strong&gt;instance variable&lt;/strong&gt; for data that belongs to one object&lt;/li&gt;
&lt;li&gt;Use a &lt;strong&gt;class variable&lt;/strong&gt; for data shared by all objects of the class&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page explains:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what each one means&lt;/li&gt;
&lt;li&gt;when each one is created&lt;/li&gt;
&lt;li&gt;how Python finds them&lt;/li&gt;
&lt;li&gt;common beginner mistakes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once you can tell the two apart, choosing the right one for your data becomes much easier.&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>Iterators and Iterable Objects Explained</title><link>https://pythonbeginner.help/learn/iterators-and-iterable-objects-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/iterators-and-iterable-objects-explained/</guid><description>&lt;h1 id="iterators-and-iterable-objects-explained"&gt;Iterators and Iterable Objects Explained&lt;/h1&gt;
&lt;p&gt;An &lt;strong&gt;iterable&lt;/strong&gt; is something you can loop over. An &lt;strong&gt;iterator&lt;/strong&gt; is the object that gives you values one at a time during that loop.&lt;/p&gt;
&lt;p&gt;This difference is important because it helps you understand:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;how &lt;code&gt;for&lt;/code&gt; loops work&lt;/li&gt;
&lt;li&gt;why &lt;code&gt;next()&lt;/code&gt; works on some objects but not others&lt;/li&gt;
&lt;li&gt;why some objects get &amp;ldquo;used up&amp;rdquo; after you loop through them&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A good short way to remember it is:&lt;/p&gt;</description></item><item><title>json.dump() Function Explained</title><link>https://pythonbeginner.help/standard-library/json.dump-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/json.dump-function-explained/</guid><description>&lt;h1 id="jsondump-function-explained"&gt;json.dump() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;json.dump()&lt;/code&gt; writes Python data to a file in JSON format.&lt;/p&gt;
&lt;p&gt;Use it when you want to save data like dictionaries or lists into a &lt;code&gt;.json&lt;/code&gt; file. This is a common way to store settings, API data, or simple structured data.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;json&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;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;Alice&amp;#34;&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;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&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;data.json&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="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;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dump&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="n"&gt;file&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;json.dump()&lt;/code&gt; when you want to write Python data directly to a file as JSON.&lt;/p&gt;</description></item><item><title>json.dumps() Function Explained</title><link>https://pythonbeginner.help/standard-library/json.dumps-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/json.dumps-function-explained/</guid><description>&lt;h1 id="jsondumps-function-explained"&gt;&lt;code&gt;json.dumps()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;json.dumps()&lt;/code&gt; converts a Python object into a JSON-formatted string.&lt;/p&gt;
&lt;p&gt;Use it when you want JSON as text, not as a file. This is common when sending data to an API, storing JSON in a variable, or printing JSON for debugging.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;json&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;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;Alice&amp;#34;&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;25&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;json_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&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&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;json_string&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="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;Alice&amp;#34;&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;25&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;json.dumps()&lt;/code&gt; when you want a JSON string, not a file. It converts Python data like dictionaries and lists into text in JSON format.&lt;/p&gt;</description></item><item><title>json.load() Function Explained</title><link>https://pythonbeginner.help/standard-library/json.load-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/json.load-function-explained/</guid><description>&lt;h1 id="jsonload-function-explained"&gt;&lt;code&gt;json.load()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;json.load()&lt;/code&gt; reads JSON data from an open file and converts it into normal Python data.&lt;/p&gt;
&lt;p&gt;Use it when your JSON is stored in a file, not in a Python string. This is a common way to load configuration files, saved data, or exported API responses.&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="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&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;data.json&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;r&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&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&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&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;type&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&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;json.load()&lt;/code&gt; when you already have an open file object. It converts JSON from the file into Python data like &lt;code&gt;dict&lt;/code&gt;, &lt;code&gt;list&lt;/code&gt;, &lt;code&gt;str&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, or &lt;code&gt;None&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>json.loads() Function Explained</title><link>https://pythonbeginner.help/standard-library/json.loads-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/json.loads-function-explained/</guid><description>&lt;h1 id="jsonloads-function-explained"&gt;&lt;code&gt;json.loads()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;json.loads()&lt;/code&gt; converts JSON text into normal Python data.&lt;/p&gt;
&lt;p&gt;Use it when your JSON is already stored in a string, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;API response text&lt;/li&gt;
&lt;li&gt;JSON copied into a variable&lt;/li&gt;
&lt;li&gt;JSON read with &lt;code&gt;file.read()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is part of Python’s built-in &lt;code&gt;json&lt;/code&gt; module.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;json&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;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;{&amp;#34;name&amp;#34;: &amp;#34;Ana&amp;#34;, &amp;#34;age&amp;#34;: 20, &amp;#34;is_student&amp;#34;: true}&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&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="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&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="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&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;type&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&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;name&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;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;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Ana&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&amp;#39;&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="s1"&gt;&amp;#39;is_student&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="err"&gt;&amp;#39;&lt;/span&gt;&lt;span class="nc"&gt;dict&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;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;Ana&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;json.loads()&lt;/code&gt; when your JSON is already in a string. It returns normal Python objects like &lt;code&gt;dict&lt;/code&gt;, &lt;code&gt;list&lt;/code&gt;, &lt;code&gt;str&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, and &lt;code&gt;None&lt;/code&gt;.&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>Lambda Functions in Python Explained</title><link>https://pythonbeginner.help/learn/lambda-functions-in-python-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/lambda-functions-in-python-explained/</guid><description>&lt;h1 id="lambda-functions-in-python-explained"&gt;Lambda Functions in Python Explained&lt;/h1&gt;
&lt;p&gt;Lambda functions are a short way to create small functions in Python.&lt;/p&gt;
&lt;p&gt;This page explains:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what a lambda function is&lt;/li&gt;
&lt;li&gt;what its syntax means&lt;/li&gt;
&lt;li&gt;where beginners usually see it&lt;/li&gt;
&lt;li&gt;when &lt;code&gt;def&lt;/code&gt; is a better choice&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are new to functions, it also helps to understand &lt;a href="https://pythonbeginner.help/glossary/what-is-a-function-in-python/"&gt;what a function is in Python&lt;/a&gt; and how &lt;a href="https://pythonbeginner.help/learn/python-functions-explained/"&gt;Python functions work&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;lambda&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 class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&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;add&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="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 class="mi"&gt;4&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;doubled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&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="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;n&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;2&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&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;doubled&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>List Comprehensions in Python Explained</title><link>https://pythonbeginner.help/learn/list-comprehensions-in-python-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/list-comprehensions-in-python-explained/</guid><description>&lt;h1 id="list-comprehensions-in-python-explained"&gt;List Comprehensions in Python Explained&lt;/h1&gt;
&lt;p&gt;A list comprehension is a short way to create a new list in Python.&lt;/p&gt;
&lt;p&gt;It lets you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;loop through values&lt;/li&gt;
&lt;li&gt;optionally filter them&lt;/li&gt;
&lt;li&gt;build a new list in one expression&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;List comprehensions are useful when you want to transform or filter data in a clear, compact way. They are best for simple cases. If the logic becomes hard to read, a normal &lt;code&gt;for&lt;/code&gt; loop is usually the better choice.&lt;/p&gt;</description></item><item><title>math.ceil() and math.floor() Explained</title><link>https://pythonbeginner.help/standard-library/math.ceil-and-math.floor-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/math.ceil-and-math.floor-explained/</guid><description>&lt;h1 id="mathceil-and-mathfloor-explained"&gt;math.ceil() and math.floor() Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;math.ceil()&lt;/code&gt; and &lt;code&gt;math.floor()&lt;/code&gt; are useful when you need to round numbers in a specific direction.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;math.ceil()&lt;/code&gt; rounds &lt;strong&gt;up&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;math.floor()&lt;/code&gt; rounds &lt;strong&gt;down&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These functions are part of Python’s &lt;a href="https://pythonbeginner.help/standard-library/python-math-module-overview/"&gt;&lt;code&gt;math&lt;/code&gt; module overview&lt;/a&gt;, so you must import &lt;code&gt;math&lt;/code&gt; before using them.&lt;/p&gt;
&lt;p&gt;If you are comparing them with &lt;code&gt;round()&lt;/code&gt;, the key difference is simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;math.ceil()&lt;/code&gt; always goes up&lt;/li&gt;
&lt;li&gt;&lt;code&gt;math.floor()&lt;/code&gt; always goes down&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbeginner.help/reference/python-round-function-explained/"&gt;&lt;code&gt;round()&lt;/code&gt;&lt;/a&gt; goes to the nearest value&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="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;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 4&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;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.8&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 3&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;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;3.8&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# -3&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;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;3.2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# -4&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;math.ceil()&lt;/code&gt; to round up to the next whole number. Use &lt;code&gt;math.floor()&lt;/code&gt; to round down to the previous whole number.&lt;/p&gt;</description></item><item><title>math.pow() Function Explained</title><link>https://pythonbeginner.help/standard-library/math.pow-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/math.pow-function-explained/</guid><description>&lt;h1 id="mathpow-function-explained"&gt;math.pow() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;math.pow()&lt;/code&gt; raises one number to the power of another.&lt;/p&gt;
&lt;p&gt;It is part of Python’s &lt;code&gt;math&lt;/code&gt; module, so you must import &lt;code&gt;math&lt;/code&gt; before using it. This function is useful when you are already working with other math functions, but beginners should also know that &lt;code&gt;math.pow()&lt;/code&gt; is different from the &lt;code&gt;**&lt;/code&gt; operator.&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="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;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;pow&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;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 8.0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;math.pow(x, y)&lt;/code&gt; returns &lt;code&gt;x&lt;/code&gt; raised to the power of &lt;code&gt;y&lt;/code&gt;. It always returns a float.&lt;/p&gt;</description></item><item><title>math.sqrt() Function Explained</title><link>https://pythonbeginner.help/standard-library/math.sqrt-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/math.sqrt-function-explained/</guid><description>&lt;h1 id="mathsqrt-function-explained"&gt;&lt;code&gt;math.sqrt()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;math.sqrt()&lt;/code&gt; returns the square root of a number in Python. It is part of the &lt;code&gt;math&lt;/code&gt; module, so you need to import that module before using it.&lt;/p&gt;
&lt;p&gt;This function is useful when writing formulas, solving geometry problems, or doing basic calculations. On this page, you will learn what &lt;code&gt;math.sqrt()&lt;/code&gt; does, what it returns, when to use it, and the most common beginner mistakes.&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="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;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;25&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 class="c1"&gt;# 5.0&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;math.sqrt()&lt;/code&gt; after importing the &lt;code&gt;math&lt;/code&gt; module. It returns a float.&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>Mutability in Python Explained (Mutable vs Immutable Types)</title><link>https://pythonbeginner.help/learn/mutability-in-python-explained-mutable-vs-immutable-types/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/mutability-in-python-explained-mutable-vs-immutable-types/</guid><description>&lt;h1 id="mutability-in-python-explained-mutable-vs-immutable-types"&gt;Mutability in Python Explained (Mutable vs Immutable Types)&lt;/h1&gt;
&lt;p&gt;Mutability describes whether a Python object can change after it is created.&lt;/p&gt;
&lt;p&gt;This matters because Python variables do not store independent copied values by default. They refer to objects. Once you understand that, many confusing results with lists, strings, and function arguments start to make sense.&lt;/p&gt;
&lt;p&gt;In this guide, you will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What mutable and immutable mean&lt;/li&gt;
&lt;li&gt;Which common Python types are mutable or immutable&lt;/li&gt;
&lt;li&gt;How assignment works with objects&lt;/li&gt;
&lt;li&gt;Why functions can sometimes change your original data&lt;/li&gt;
&lt;li&gt;How to avoid common bugs&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="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;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;y&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="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;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# [1, 2, 3]&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;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="n"&gt;new_name&lt;/span&gt; &lt;span class="o"&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;upper&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="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Sam&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;new_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# SAM&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Lists can change in place. Strings cannot. Many beginner mistakes come from not knowing this difference.&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>Object-Oriented Programming in Python Explained</title><link>https://pythonbeginner.help/learn/object-oriented-programming-in-python-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/object-oriented-programming-in-python-explained/</guid><description>&lt;h1 id="object-oriented-programming-in-python-explained"&gt;Object-Oriented Programming in Python Explained&lt;/h1&gt;
&lt;p&gt;Object-oriented programming, usually called &lt;strong&gt;OOP&lt;/strong&gt;, is a way to organize Python code using &lt;strong&gt;classes&lt;/strong&gt; and &lt;strong&gt;objects&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For beginners, the main idea is simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;class&lt;/strong&gt; describes what something should look like and do&lt;/li&gt;
&lt;li&gt;An &lt;strong&gt;object&lt;/strong&gt; is one real thing created from that class&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;OOP helps you keep related data and behavior together. It is useful in bigger programs, and you will see it often in real Python code, libraries, and tutorials.&lt;/p&gt;</description></item><item><title>os.chdir() Function Explained</title><link>https://pythonbeginner.help/standard-library/os.chdir-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/os.chdir-function-explained/</guid><description>&lt;h1 id="oschdir-function-explained"&gt;os.chdir() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;os.chdir()&lt;/code&gt; changes Python’s current working directory.&lt;/p&gt;
&lt;p&gt;This matters because the current working directory is the folder Python uses when you give a &lt;strong&gt;relative path&lt;/strong&gt; like &lt;code&gt;&amp;quot;data.txt&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;images/photo.jpg&amp;quot;&lt;/code&gt;. After you change directories, file operations such as &lt;code&gt;open()&lt;/code&gt; will use the new folder.&lt;/p&gt;
&lt;p&gt;If you are learning how files and folders work in Python, &lt;code&gt;os.chdir()&lt;/code&gt; can be useful. But it can also cause confusion if you are not sure which folder your program is currently using.&lt;/p&gt;</description></item><item><title>os.getcwd() Function Explained</title><link>https://pythonbeginner.help/standard-library/os.getcwd-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/os.getcwd-function-explained/</guid><description>&lt;h1 id="osgetcwd-function-explained"&gt;os.getcwd() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;os.getcwd()&lt;/code&gt; returns the current working directory in Python.&lt;/p&gt;
&lt;p&gt;This is useful when you want to know which folder Python is currently using. It matters because relative file paths are based on this folder. If your code opens or saves files using names like &lt;code&gt;&amp;quot;data.txt&amp;quot;&lt;/code&gt;, Python will look in the current working directory unless you give a full path.&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="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;current_folder&lt;/span&gt; &lt;span class="o"&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;getcwd&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;current_folder&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;os.getcwd()&lt;/code&gt; to get the current working directory as a string.&lt;/p&gt;</description></item><item><title>os.listdir() Function Explained</title><link>https://pythonbeginner.help/standard-library/os.listdir-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/os.listdir-function-explained/</guid><description>&lt;h1 id="oslistdir-function-explained"&gt;os.listdir() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;os.listdir()&lt;/code&gt; gives you the names of files and folders inside a directory.&lt;/p&gt;
&lt;p&gt;It is a useful function when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;see what is inside a folder&lt;/li&gt;
&lt;li&gt;loop through files&lt;/li&gt;
&lt;li&gt;build file paths for later work&lt;/li&gt;
&lt;li&gt;check directory contents before opening files&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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;items&lt;/span&gt; &lt;span class="o"&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="s1"&gt;&amp;#39;.&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;items&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 lists the names of files and folders in the current directory.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="what-oslistdir-does"&gt;What os.listdir() does &lt;a class="heading-anchor" href="#what-oslistdir-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;os.listdir()&lt;/code&gt; returns the names inside a directory.&lt;/p&gt;</description></item><item><title>os.path.exists() Function Explained</title><link>https://pythonbeginner.help/standard-library/os.path.exists-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/os.path.exists-function-explained/</guid><description>&lt;h1 id="ospathexists-function-explained"&gt;os.path.exists() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;os.path.exists()&lt;/code&gt; checks whether a path exists in Python.&lt;/p&gt;
&lt;p&gt;You can use it to test:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;whether a file exists&lt;/li&gt;
&lt;li&gt;whether a folder exists&lt;/li&gt;
&lt;li&gt;whether a path is missing&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is useful before you try to open, delete, rename, or work with a path.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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;example.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;exists&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="s2"&gt;&amp;#34;Path exists&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;Path does not exist&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 this to quickly check whether a file or folder path exists before trying to open or use it.&lt;/p&gt;</description></item><item><title>os.path.join() Function Explained</title><link>https://pythonbeginner.help/standard-library/os.path.join-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/os.path.join-function-explained/</guid><description>&lt;h1 id="ospathjoin-function-explained"&gt;os.path.join() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;os.path.join()&lt;/code&gt; combines file and folder names into a single path string.&lt;/p&gt;
&lt;p&gt;Beginners should use it instead of joining path parts by hand because it uses the correct path separator for the current operating system. This helps you avoid mistakes with &lt;code&gt;/&lt;/code&gt; and &lt;code&gt;\&lt;/code&gt; when your code runs on different computers.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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;file_path&lt;/span&gt; &lt;span class="o"&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;path&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="s2"&gt;&amp;#34;data&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;reports&amp;#34;&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&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;file_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;
&lt;ul&gt;
&lt;li&gt;Combines &lt;code&gt;&amp;quot;data&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;reports&amp;quot;&lt;/code&gt;, and &lt;code&gt;&amp;quot;output.txt&amp;quot;&lt;/code&gt; into one path&lt;/li&gt;
&lt;li&gt;Returns the path as a string&lt;/li&gt;
&lt;li&gt;Does &lt;strong&gt;not&lt;/strong&gt; create the file or folder&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On one system, the output might look like this:&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>Python abs() Function Explained</title><link>https://pythonbeginner.help/reference/python-abs-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-abs-function-explained/</guid><description>&lt;h1 id="python-abs-function-explained"&gt;Python abs() Function Explained&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;abs()&lt;/code&gt; function returns the absolute value of a number.&lt;/p&gt;
&lt;p&gt;Beginners usually use it when they want:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a number without its negative sign&lt;/li&gt;
&lt;li&gt;the distance between two numbers&lt;/li&gt;
&lt;li&gt;the size of a value without caring whether it is positive or negative&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It works with common Python number types such as integers, floats, and complex numbers.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;7&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="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.5&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="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="n"&gt;j&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="mi"&gt;7&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="mf"&gt;3.5&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="mf"&gt;3.605551275463989&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;abs()&lt;/code&gt; to get the absolute value of a number. For complex numbers, it returns the magnitude.&lt;/p&gt;</description></item><item><title>Python all() Function Explained</title><link>https://pythonbeginner.help/reference/python-all-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-all-function-explained/</guid><description>&lt;h1 id="python-all-function-explained"&gt;Python &lt;code&gt;all()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;Python’s &lt;code&gt;all()&lt;/code&gt; function checks whether every item in an iterable is truthy.&lt;/p&gt;
&lt;p&gt;It is a small function, but it causes a lot of beginner confusion because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;it works with truthy and falsy values&lt;/li&gt;
&lt;li&gt;it takes one iterable argument&lt;/li&gt;
&lt;li&gt;&lt;code&gt;all([])&lt;/code&gt; returns &lt;code&gt;True&lt;/code&gt;, which often seems strange at first&lt;/li&gt;
&lt;/ul&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="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="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;all&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&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 class="c1"&gt;# True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;all()&lt;/code&gt; returns &lt;code&gt;True&lt;/code&gt; only if every item in the iterable is truthy. If even one item is falsy, it returns &lt;code&gt;False&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Python any() Function Explained</title><link>https://pythonbeginner.help/reference/python-any-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-any-function-explained/</guid><description>&lt;h1 id="python-any-function-explained"&gt;Python any() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;any()&lt;/code&gt; is a built-in Python function that checks an iterable and tells you whether &lt;strong&gt;at least one item is truthy&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;You will usually use it with values like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;lists&lt;/li&gt;
&lt;li&gt;tuples&lt;/li&gt;
&lt;li&gt;sets&lt;/li&gt;
&lt;li&gt;strings&lt;/li&gt;
&lt;li&gt;generator expressions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is useful when you want a quick &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt; answer without writing a full loop.&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;values&lt;/span&gt; &lt;span class="o"&gt;=&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="s1"&gt;&amp;#39;&amp;#39;&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;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;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# True&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;any(iterable)&lt;/code&gt; when you want &lt;code&gt;True&lt;/code&gt; if at least one item in the iterable is truthy.&lt;/p&gt;</description></item><item><title>Python API POST Request Example</title><link>https://pythonbeginner.help/examples/python-api-post-request-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-api-post-request-example/</guid><description>&lt;h1 id="python-api-post-request-example"&gt;Python API POST Request Example&lt;/h1&gt;
&lt;p&gt;This example shows how to send a POST request in Python, send data to an API, and read the response.&lt;/p&gt;
&lt;p&gt;The goal is to give you one simple working example you can run right away. If you want a more general guide later, see &lt;a href="https://pythonbeginner.help/how-to/how-to-send-a-post-request-in-python/"&gt;how to send a POST request in Python&lt;/a&gt; or &lt;a href="https://pythonbeginner.help/how-to/how-to-make-an-api-request-in-python/"&gt;how to make an API request in Python&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;requests&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;https://httpbin.org/post&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;payload&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 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;Alice&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="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&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="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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&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;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&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 sends JSON data to a test API and prints the status code and returned JSON.&lt;/p&gt;</description></item><item><title>Python API Request Example (GET Request)</title><link>https://pythonbeginner.help/examples/python-api-request-example-get-request/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-api-request-example-get-request/</guid><description>&lt;h1 id="python-api-request-example-get-request"&gt;Python API Request Example (GET Request)&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to make a simple GET request in Python, read the response, and handle basic problems.&lt;/p&gt;
&lt;p&gt;If you want the fastest working version first, use 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="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;requests&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;https://api.github.com/users/octocat&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&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="n"&gt;url&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&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;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&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 example uses the &lt;code&gt;requests&lt;/code&gt; package and prints:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The HTTP status code&lt;/li&gt;
&lt;li&gt;The JSON response from the API&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="what-this-example-does"&gt;What this example does &lt;a class="heading-anchor" href="#what-this-example-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This example is useful because it shows the basic pattern for working with APIs in Python.&lt;/p&gt;</description></item><item><title>Python Argument Parser Example (argparse)</title><link>https://pythonbeginner.help/examples/python-argument-parser-example-argparse/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-argument-parser-example-argparse/</guid><description>&lt;h1 id="python-argument-parser-example-argparse"&gt;Python Argument Parser Example (argparse)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;argparse&lt;/code&gt; helps you build Python programs that accept values from the command line.&lt;/p&gt;
&lt;p&gt;This example shows one small, practical script so you can learn the basic idea without learning the whole module at once. You will see how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;accept arguments after the script name&lt;/li&gt;
&lt;li&gt;convert values to the right type&lt;/li&gt;
&lt;li&gt;show built-in help&lt;/li&gt;
&lt;li&gt;use an optional flag&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Here is a simple script that adds two numbers:&lt;/p&gt;</description></item><item><title>Python Basic Class Example (OOP)</title><link>https://pythonbeginner.help/examples/python-basic-class-example-oop/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-basic-class-example-oop/</guid><description>&lt;h1 id="python-basic-class-example-oop"&gt;Python Basic Class Example (OOP)&lt;/h1&gt;
&lt;p&gt;This page shows a simple Python class example for beginners.&lt;/p&gt;
&lt;p&gt;You will learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a class&lt;/li&gt;
&lt;li&gt;Make an object from that class&lt;/li&gt;
&lt;li&gt;Store data in attributes&lt;/li&gt;
&lt;li&gt;Add behavior with a method&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;__init__&lt;/code&gt; to set starting values&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are new to classes, this is a good first example because it uses a small real-world idea and keeps the code short.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&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;def&lt;/span&gt; &lt;span class="fm"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&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 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 class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&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;name&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;age&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;bark&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&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="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; says woof!&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="n"&gt;my_dog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Max&amp;#34;&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;my_dog&lt;/span&gt;&lt;span class="o"&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="n"&gt;my_dog&lt;/span&gt;&lt;span class="o"&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 class="n"&gt;my_dog&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bark&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>Python bool() Function Explained</title><link>https://pythonbeginner.help/reference/python-bool-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-bool-function-explained/</guid><description>&lt;h1 id="python-bool-function-explained"&gt;Python bool() Function Explained&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;bool()&lt;/code&gt; function converts a value to either &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is useful when you want to check whether a value counts as &amp;ldquo;true&amp;rdquo; or &amp;ldquo;false&amp;rdquo; in Python. Beginners often use &lt;code&gt;bool()&lt;/code&gt; to understand how values behave in &lt;code&gt;if&lt;/code&gt; statements and other conditions.&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;bool&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&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;bool&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 class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;bool&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 class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;bool&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;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;bool&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="nb"&gt;bool&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Expected 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="kc"&gt;False&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kc"&gt;False&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kc"&gt;False&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kc"&gt;True&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;bool(value)&lt;/code&gt; to convert a value to &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;. Empty and zero-like values become &lt;code&gt;False&lt;/code&gt;. Most other values become &lt;code&gt;True&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Python Booleans Explained (True and False)</title><link>https://pythonbeginner.help/learn/python-booleans-explained-true-and-false/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-booleans-explained-true-and-false/</guid><description>&lt;h1 id="python-booleans-explained-true-and-false"&gt;Python Booleans Explained (True and False)&lt;/h1&gt;
&lt;p&gt;Boolean values are one of the most important parts of Python.&lt;/p&gt;
&lt;p&gt;A Boolean is simply a value that is either &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;. You will use Booleans when checking conditions, comparing values, and controlling what your program does next.&lt;/p&gt;
&lt;p&gt;If you are new to Python, this is the foundation you need before moving on to &lt;a href="https://pythonbeginner.help/learn/python-if-statements-explained/"&gt;Python if statements explained&lt;/a&gt; and comparisons.&lt;/p&gt;
&lt;p&gt;Below we cover how Booleans are created, the operators that produce them, and how Python decides what counts as true or false.&lt;/p&gt;</description></item><item><title>Python break and continue Statements</title><link>https://pythonbeginner.help/learn/python-break-and-continue-statements/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-break-and-continue-statements/</guid><description>&lt;h1 id="python-break-and-continue-statements"&gt;Python break and continue Statements&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt; are used inside loops to control what happens next.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;break&lt;/code&gt; stops the loop completely&lt;/li&gt;
&lt;li&gt;&lt;code&gt;continue&lt;/code&gt; skips the current loop step and moves to the next one&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These statements work in both &lt;code&gt;for&lt;/code&gt; loops and &lt;code&gt;while&lt;/code&gt; loops. They are useful when you want more control over loop behavior without rewriting the whole loop.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;for&lt;/span&gt; &lt;span class="n"&gt;number&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;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&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;number&lt;/span&gt; &lt;span class="o"&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="k"&gt;continue&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;number&lt;/span&gt; &lt;span class="o"&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;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;break&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Output:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# 1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# 2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# 4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure class="diagram" role="group" aria-label="continue skips a step and break ends the loop early."&gt;
&lt;svg width="691" height="298" viewBox="0 0 691 298" class="d-svg" xmlns="http://www.w3.org/2000/svg" role="img"&gt;
 &lt;defs&gt;&lt;marker id="flowarrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"&gt;&lt;path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/&gt;&lt;/marker&gt;&lt;/defs&gt;&lt;line x1="230" y1="6" x2="230" y2="16" class="d-edge"/&gt;&lt;polygon points="230,16 350,50 230,84 110,50" class="d-decision"/&gt;
 &lt;text x="230" y="50" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;more numbers left&lt;/text&gt;&lt;line x1="230" y1="84" x2="230" y2="150" class="d-edge" marker-end="url(#flowarrow)"/&gt;
 &lt;text x="238" y="102" class="d-edge-label"&gt;True&lt;/text&gt;
 &lt;rect x="88" y="150" width="285" height="44" rx="8" class="d-node"/&gt;
 &lt;text x="230" y="172" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;skip 3, stop at 5, else print&lt;/text&gt;&lt;line x1="230" y1="194" x2="230" y2="240" class="d-edge" marker-end="url(#flowarrow)"/&gt;
 &lt;rect x="88" y="240" width="285" height="44" rx="8" class="d-node"/&gt;
 &lt;text x="230" y="262" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;next number&lt;/text&gt;&lt;path d="M88 284 H30 V50 H110" class="d-edge" marker-end="url(#flowarrow)" fill="none"/&gt;
 &lt;text x="36" y="165" class="d-edge-label"&gt;repeat&lt;/text&gt;&lt;line x1="350" y1="50" x2="390" y2="50" class="d-edge" marker-end="url(#flowarrow)"/&gt;
 &lt;text x="362" y="42" class="d-edge-label"&gt;False&lt;/text&gt;
 &lt;rect x="390" y="28" width="285" height="44" rx="8" class="d-node"/&gt;
 &lt;text x="532" y="50" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;after the loop&lt;/text&gt;
&lt;/svg&gt;&lt;figcaption&gt;continue skips a step and break ends the loop early.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Use &lt;code&gt;continue&lt;/code&gt; to skip the current loop step. Use &lt;code&gt;break&lt;/code&gt; to stop the loop completely.&lt;/p&gt;</description></item><item><title>Python Classes and Objects Explained</title><link>https://pythonbeginner.help/learn/python-classes-and-objects-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-classes-and-objects-explained/</guid><description>&lt;h1 id="python-classes-and-objects-explained"&gt;Python Classes and Objects Explained&lt;/h1&gt;
&lt;p&gt;Classes and objects are a big part of Python, but the basic idea is simple.&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;class&lt;/strong&gt; is a blueprint. An &lt;strong&gt;object&lt;/strong&gt; is one real thing made from that blueprint.&lt;/p&gt;
&lt;p&gt;If that sounds abstract, do not worry. This page shows what classes and objects mean, how they work together, and how to use them in simple Python code.&lt;/p&gt;
&lt;p&gt;We will build up from a tiny class to a full example, then put it into practice at the end.&lt;/p&gt;</description></item><item><title>Python Command Line Tool Example</title><link>https://pythonbeginner.help/examples/python-command-line-tool-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-command-line-tool-example/</guid><description>&lt;h1 id="python-command-line-tool-example"&gt;Python Command Line Tool Example&lt;/h1&gt;
&lt;p&gt;A command line tool is a Python script that you run from the terminal and give input to when the script starts.&lt;/p&gt;
&lt;p&gt;This beginner-friendly example shows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;how to build a small Python CLI tool&lt;/li&gt;
&lt;li&gt;how to read command line arguments with &lt;a href="https://pythonbeginner.help/standard-library/sys.argv-explained"&gt;&lt;code&gt;sys.argv&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;how to handle missing or invalid input&lt;/li&gt;
&lt;li&gt;how to run the script from the terminal&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are new to this, the main idea is simple: the user runs a file like &lt;code&gt;python tool.py Alice&lt;/code&gt;, and your script uses &lt;code&gt;Alice&lt;/code&gt; as input.&lt;/p&gt;</description></item><item><title>Python Comments Explained (Single-Line and Multi-Line)</title><link>https://pythonbeginner.help/learn/python-comments-explained-single-line-and-multi-line/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-comments-explained-single-line-and-multi-line/</guid><description>&lt;h1 id="python-comments-explained-single-line-and-multi-line"&gt;Python Comments Explained (Single-Line and Multi-Line)&lt;/h1&gt;
&lt;p&gt;Comments help you write code that is easier to read and understand.&lt;/p&gt;
&lt;p&gt;In Python, comments are notes for humans. Python ignores them when it runs your program. This makes comments useful for explaining what your code does, why it exists, or what to watch out for.&lt;/p&gt;
&lt;p&gt;This page shows you how to write comments in Python, when to use them, and how to avoid confusing comments with triple-quoted strings.&lt;/p&gt;</description></item><item><title>Python Contact Book Example</title><link>https://pythonbeginner.help/examples/python-contact-book-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-contact-book-example/</guid><description>&lt;h1 id="python-contact-book-example"&gt;Python Contact Book Example&lt;/h1&gt;
&lt;p&gt;A small contact book project is a great way to practice Python basics.&lt;/p&gt;
&lt;p&gt;In this example, you will build a simple command-line program that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;stores contact names and phone numbers&lt;/li&gt;
&lt;li&gt;asks the user for input&lt;/li&gt;
&lt;li&gt;searches for contacts&lt;/li&gt;
&lt;li&gt;deletes contacts&lt;/li&gt;
&lt;li&gt;repeats with a menu until the user exits&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This project is beginner-friendly because it uses a few core ideas in a practical way.&lt;/p&gt;
&lt;h2 id="what-this-project-builds"&gt;What this project builds &lt;a class="heading-anchor" href="#what-this-project-builds" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This example creates:&lt;/p&gt;</description></item><item><title>Python Countdown Timer Example</title><link>https://pythonbeginner.help/examples/python-countdown-timer-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-countdown-timer-example/</guid><description>&lt;h1 id="python-countdown-timer-example"&gt;Python Countdown Timer Example&lt;/h1&gt;
&lt;p&gt;A countdown timer is a great beginner Python project. It helps you practice variables, loops, and pauses with &lt;code&gt;sleep()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This example shows how to build a simple countdown timer that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;counts down one number at a time&lt;/li&gt;
&lt;li&gt;waits 1 second between numbers&lt;/li&gt;
&lt;li&gt;prints a final message when it finishes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Start with the basic version first. Once it works, you can safely change the starting number or add user input.&lt;/p&gt;</description></item><item><title>Python CSV Reader Example</title><link>https://pythonbeginner.help/examples/python-csv-reader-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-csv-reader-example/</guid><description>&lt;h1 id="python-csv-reader-example"&gt;Python CSV Reader Example&lt;/h1&gt;
&lt;p&gt;This example shows how to read a CSV file in Python with the built-in &lt;code&gt;csv&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;It focuses on one simple working script:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;open a CSV file&lt;/li&gt;
&lt;li&gt;read each row&lt;/li&gt;
&lt;li&gt;print the row&lt;/li&gt;
&lt;li&gt;understand what the output means&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want the fastest working example, start here:&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;csv&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="s1"&gt;&amp;#39;data.csv&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newline&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;#39;&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="s1"&gt;&amp;#39;utf-8&amp;#39;&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;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;(&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;reader&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;row&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 when you want the quickest way to read rows from a CSV file.&lt;/p&gt;</description></item><item><title>Python CSV Writer Example</title><link>https://pythonbeginner.help/examples/python-csv-writer-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-csv-writer-example/</guid><description>&lt;h1 id="python-csv-writer-example"&gt;Python CSV Writer Example&lt;/h1&gt;
&lt;p&gt;This example shows how to write rows to a CSV file in Python with the built-in &lt;code&gt;csv&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;You will create a simple file named &lt;code&gt;people.csv&lt;/code&gt;, write a header row and some data rows, and see what the finished file looks like. This is a good starting point if you want to export table-like data from a Python script.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;csv&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;rows&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 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;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;city&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="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Alice&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;London&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="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Bob&amp;#34;&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 class="s2"&gt;&amp;#34;Paris&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="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Charlie&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Berlin&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="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;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;people.csv&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;newline&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="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;writer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;writer&lt;/span&gt;&lt;span class="p"&gt;(&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;writer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;writerows&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;CSV file written successfully&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;&lt;strong&gt;Note:&lt;/strong&gt; Use &lt;code&gt;newline=&amp;quot;&amp;quot;&lt;/code&gt; when opening the file. This helps avoid blank lines in CSV output on some systems.&lt;/p&gt;</description></item><item><title>Python Data Cleaning Script Example</title><link>https://pythonbeginner.help/examples/python-data-cleaning-script-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-data-cleaning-script-example/</guid><description>&lt;h1 id="python-data-cleaning-script-example"&gt;Python Data Cleaning Script Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows one practical Python data cleaning script.&lt;/p&gt;
&lt;p&gt;You will start with messy data stored as a list of dictionaries, then clean it by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;removing extra spaces&lt;/li&gt;
&lt;li&gt;standardizing text&lt;/li&gt;
&lt;li&gt;handling missing values&lt;/li&gt;
&lt;li&gt;converting strings to numbers&lt;/li&gt;
&lt;li&gt;building a new clean result&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a useful pattern when you want to clean data before saving it, analyzing it, or using it in another part of your program.&lt;/p&gt;</description></item><item><title>Python Data Types Overview</title><link>https://pythonbeginner.help/learn/python-data-types-overview/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-data-types-overview/</guid><description>&lt;h1 id="python-data-types-overview"&gt;Python Data Types Overview&lt;/h1&gt;
&lt;p&gt;Python has different &lt;strong&gt;data types&lt;/strong&gt; for different kinds of values.&lt;/p&gt;
&lt;p&gt;This beginner-friendly overview explains what data types are, why they matter, and how to recognize the most common built-in types. You do not need to memorize everything at once. The goal is to understand the basic idea and know which types you will use most often.&lt;/p&gt;
&lt;h2 id="quick-way-to-check-a-type"&gt;Quick way to check a type &lt;a class="heading-anchor" href="#quick-way-to-check-a-type" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use &lt;code&gt;type()&lt;/code&gt; to quickly check what kind of value you are working with.&lt;/p&gt;</description></item><item><title>Python datetime Module Overview</title><link>https://pythonbeginner.help/standard-library/python-datetime-module-overview/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/python-datetime-module-overview/</guid><description>&lt;h1 id="python-datetime-module-overview"&gt;Python datetime Module Overview&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;datetime&lt;/code&gt; module helps you work with dates, times, and time differences in Python.&lt;/p&gt;
&lt;p&gt;It is part of the Python standard library, so you do not need to install anything extra. Beginners often use it to get the current date, create a specific date, format a date as text, or add a number of days to a date.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timedelta&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;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&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;today&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;today&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;meeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;14&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;one_week&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;7&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&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;today&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;meeting&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;now&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;one_week&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 code does:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>Python Decorator Example (Simple Use Case)</title><link>https://pythonbeginner.help/examples/python-decorator-example-simple-use-case/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-decorator-example-simple-use-case/</guid><description>&lt;h1 id="python-decorator-example-simple-use-case"&gt;Python Decorator Example (Simple Use Case)&lt;/h1&gt;
&lt;p&gt;If you are new to decorators, the easiest way to understand them is to see one small example that works.&lt;/p&gt;
&lt;p&gt;This page shows a simple decorator that wraps a function, runs code before and after it, and helps you see why decorators are useful. It does &lt;strong&gt;not&lt;/strong&gt; try to cover every decorator pattern.&lt;/p&gt;
&lt;h2 id="page-goal"&gt;Page goal &lt;a class="heading-anchor" href="#page-goal" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This example focuses on one clear idea:&lt;/p&gt;</description></item><item><title>Python dict() Function Explained</title><link>https://pythonbeginner.help/reference/python-dict-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dict-function-explained/</guid><description>&lt;h1 id="python-dict-function-explained"&gt;Python &lt;code&gt;dict()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The built-in &lt;code&gt;dict()&lt;/code&gt; function creates a new dictionary.&lt;/p&gt;
&lt;p&gt;A dictionary stores data as &lt;strong&gt;key-value pairs&lt;/strong&gt;. You use it when you want to connect one piece of data to another, such as a name to an age or a product to a price.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;dict()&lt;/code&gt; is commonly used to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;create an empty dictionary&lt;/li&gt;
&lt;li&gt;convert key-value pairs into a dictionary&lt;/li&gt;
&lt;li&gt;build a dictionary from keyword arguments&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are new to dictionaries, see &lt;a href="https://pythonbeginner.help/learn/python-dictionaries-explained/"&gt;Python dictionaries explained&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python Dictionaries Explained</title><link>https://pythonbeginner.help/learn/python-dictionaries-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-dictionaries-explained/</guid><description>&lt;h1 id="python-dictionaries-explained"&gt;Python Dictionaries Explained&lt;/h1&gt;
&lt;p&gt;A Python dictionary stores data as &lt;strong&gt;key-value pairs&lt;/strong&gt;. It is one of the most useful built-in data types in Python.&lt;/p&gt;
&lt;p&gt;Dictionaries are great when your data has labels such as &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;age&lt;/code&gt;, or &lt;code&gt;price&lt;/code&gt;. Instead of finding a value by position, you look it up by its key.&lt;/p&gt;
&lt;p&gt;For example:&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;student&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 class="s2"&gt;&amp;#34;age&amp;#34;&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&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In this dictionary:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;name&amp;quot;&lt;/code&gt; is a key, and &lt;code&gt;&amp;quot;Ana&amp;quot;&lt;/code&gt; is its value&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;age&amp;quot;&lt;/code&gt; is a key, and &lt;code&gt;20&lt;/code&gt; is its value&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are completely new to the term, see &lt;a href="https://pythonbeginner.help/glossary/what-is-a-dictionary-in-python/"&gt;what a dictionary in Python is&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python Dictionary clear() Method</title><link>https://pythonbeginner.help/reference/python-dictionary-clear-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-clear-method/</guid><description>&lt;h1 id="python-dictionary-clear-method"&gt;Python Dictionary &lt;code&gt;clear()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;dict.clear()&lt;/code&gt; removes all items from a dictionary.&lt;/p&gt;
&lt;p&gt;Use it when you want to empty a dictionary without replacing the variable with a new dictionary. This method changes the original dictionary &lt;strong&gt;in place&lt;/strong&gt;, which means the same dictionary object is kept, but all key-value pairs are removed.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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 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;data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clear&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="c1"&gt;# {}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;clear()&lt;/code&gt; removes all items from the same dictionary object.&lt;/p&gt;
&lt;h2 id="what-clear-does"&gt;What &lt;code&gt;clear()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-clear-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;clear()&lt;/code&gt; method:&lt;/p&gt;</description></item><item><title>Python Dictionary copy() Method</title><link>https://pythonbeginner.help/reference/python-dictionary-copy-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-copy-method/</guid><description>&lt;h1 id="python-dictionary-copy-method"&gt;Python Dictionary &lt;code&gt;copy()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;dict.copy()&lt;/code&gt; creates a new dictionary with the same key-value pairs as the original.&lt;/p&gt;
&lt;p&gt;This method is useful when you want a separate dictionary object instead of another variable pointing to the same dictionary. It is important to know that &lt;code&gt;copy()&lt;/code&gt; makes a &lt;strong&gt;shallow copy&lt;/strong&gt;, not a deep copy.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;student&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 class="s2"&gt;&amp;#34;age&amp;#34;&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;student_copy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;copy&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;student_copy&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;student_copy&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;student&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;
&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;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Ana&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&amp;#39;&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kc"&gt;False&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;copy()&lt;/code&gt; to create a new dictionary object with the same contents. The result is a shallow copy, not a deep copy.&lt;/p&gt;</description></item><item><title>Python Dictionary fromkeys() Method</title><link>https://pythonbeginner.help/reference/python-dictionary-fromkeys-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-fromkeys-method/</guid><description>&lt;h1 id="python-dictionary-fromkeys-method"&gt;Python Dictionary &lt;code&gt;fromkeys()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;dict.fromkeys()&lt;/code&gt; creates a new dictionary from a group of keys.&lt;/p&gt;
&lt;p&gt;It is useful when you already know the keys you want, and every key should start with the same value.&lt;/p&gt;
&lt;p&gt;One important beginner mistake to watch for is using a mutable value like a list or dictionary. In that case, all keys share the same object.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;keys&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;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;city&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fromkeys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;unknown&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;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="c1"&gt;# {&amp;#39;name&amp;#39;: &amp;#39;unknown&amp;#39;, &amp;#39;age&amp;#39;: &amp;#39;unknown&amp;#39;, &amp;#39;city&amp;#39;: &amp;#39;unknown&amp;#39;}&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.fromkeys(iterable, value)&lt;/code&gt; to create a new dictionary where each key starts with the same value.&lt;/p&gt;</description></item><item><title>Python Dictionary get() Method</title><link>https://pythonbeginner.help/reference/python-dictionary-get-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-get-method/</guid><description>&lt;h1 id="python-dictionary-get-method"&gt;Python Dictionary &lt;code&gt;get()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The dictionary &lt;code&gt;get()&lt;/code&gt; method lets you safely read a value from a dictionary.&lt;/p&gt;
&lt;p&gt;It is useful when a key might be missing. Instead of crashing with a &lt;code&gt;KeyError&lt;/code&gt;, &lt;code&gt;get()&lt;/code&gt; returns &lt;code&gt;None&lt;/code&gt; by default, or a custom fallback value if you provide one.&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;person&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 class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&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;name&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Ana&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;person&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;city&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;person&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;city&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;N/A&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# N/A&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;get()&lt;/code&gt; when a dictionary key may be missing and you want a safe result instead of a &lt;code&gt;KeyError&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Python Dictionary items() Method</title><link>https://pythonbeginner.help/reference/python-dictionary-items-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-items-method/</guid><description>&lt;h1 id="python-dictionary-items-method"&gt;Python Dictionary &lt;code&gt;items()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;dict.items()&lt;/code&gt; method lets you get both the keys and values from a dictionary at the same time.&lt;/p&gt;
&lt;p&gt;Beginners usually use it when looping through a dictionary. Instead of getting a key first and then looking up its value, &lt;code&gt;items()&lt;/code&gt; gives you each key-value pair together.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;person&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 class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&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;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&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;key&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;
&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="n"&gt;Ana&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="mi"&gt;25&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;items()&lt;/code&gt; when you need both the dictionary key and its value in the same loop.&lt;/p&gt;</description></item><item><title>Python Dictionary keys() Method</title><link>https://pythonbeginner.help/reference/python-dictionary-keys-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-keys-method/</guid><description>&lt;h1 id="python-dictionary-keys-method"&gt;Python Dictionary &lt;code&gt;keys()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python dictionary &lt;code&gt;keys()&lt;/code&gt; method returns all keys from a dictionary.&lt;/p&gt;
&lt;p&gt;It is useful when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;view the available keys&lt;/li&gt;
&lt;li&gt;loop through dictionary keys&lt;/li&gt;
&lt;li&gt;check what fields exist in a dictionary&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;keys()&lt;/code&gt; does not return a regular list. It returns a special object called &lt;code&gt;dict_keys&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;student&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 class="s2"&gt;&amp;#34;age&amp;#34;&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;keys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keys&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;keys&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="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;keys&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;
&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;dict_keys&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&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;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&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;Use &lt;code&gt;keys()&lt;/code&gt; to get a view of all dictionary keys. Convert it to a list if you want a regular list output.&lt;/p&gt;</description></item><item><title>Python Dictionary pop() Method</title><link>https://pythonbeginner.help/reference/python-dictionary-pop-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-pop-method/</guid><description>&lt;h1 id="python-dictionary-pop-method"&gt;Python Dictionary &lt;code&gt;pop()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;dict.pop()&lt;/code&gt; removes a key from a dictionary and returns the value that was stored under that key.&lt;/p&gt;
&lt;p&gt;This method is useful when you want to delete a key and still keep its value for later use. It is also a common way to remove a key safely when you provide a default value.&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="n"&gt;person&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 class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&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;removed_age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pop&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;removed_age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&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;person&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# {&amp;#39;name&amp;#39;: &amp;#39;Ana&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;# Safe version with default value&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;country&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;country&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Not found&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;country&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Not found&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;pop(key)&lt;/code&gt; to remove a key and get its value. Use &lt;code&gt;pop(key, default)&lt;/code&gt; to avoid a &lt;code&gt;KeyError&lt;/code&gt; when the key might not exist.&lt;/p&gt;</description></item><item><title>Python Dictionary popitem() Method</title><link>https://pythonbeginner.help/reference/python-dictionary-popitem-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-popitem-method/</guid><description>&lt;h1 id="python-dictionary-popitem-method"&gt;Python Dictionary &lt;code&gt;popitem()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;popitem()&lt;/code&gt; method removes one item from a dictionary and returns it.&lt;/p&gt;
&lt;p&gt;It is useful when you want to both:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;remove an item&lt;/li&gt;
&lt;li&gt;get that removed item at the same time&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In modern Python, &lt;code&gt;popitem()&lt;/code&gt; removes the &lt;strong&gt;last inserted key-value pair&lt;/strong&gt;. It also changes the original dictionary, so the item is no longer there after the method runs.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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 class="mi"&gt;2&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 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="n"&gt;item&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&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 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&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>Python Dictionary Processing Example</title><link>https://pythonbeginner.help/examples/python-dictionary-processing-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-dictionary-processing-example/</guid><description>&lt;h1 id="python-dictionary-processing-example"&gt;Python Dictionary Processing Example&lt;/h1&gt;
&lt;p&gt;This example shows how to process data stored in a Python dictionary.&lt;/p&gt;
&lt;p&gt;You will use a small dictionary of student scores and learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;read values by key&lt;/li&gt;
&lt;li&gt;update an existing value&lt;/li&gt;
&lt;li&gt;add a new key-value pair&lt;/li&gt;
&lt;li&gt;loop through all entries&lt;/li&gt;
&lt;li&gt;calculate a simple result from the data&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is &lt;strong&gt;not&lt;/strong&gt; a full dictionary tutorial. It is one practical example that helps you see how dictionaries work in a small script. If you want the full concept, see &lt;a href="https://pythonbeginner.help/learn/python-dictionaries-explained/"&gt;Python dictionaries explained&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python Dictionary update() Method</title><link>https://pythonbeginner.help/reference/python-dictionary-update-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-update-method/</guid><description>&lt;h1 id="python-dictionary-update-method"&gt;Python Dictionary &lt;code&gt;update()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;update()&lt;/code&gt; method changes a dictionary by adding new key-value pairs or replacing existing values.&lt;/p&gt;
&lt;p&gt;Use it when you want to modify an existing dictionary instead of creating a new one.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;person&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 class="s2"&gt;&amp;#34;age&amp;#34;&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;update&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;21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;city&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Lima&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;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="c1"&gt;# {&amp;#39;name&amp;#39;: &amp;#39;Ana&amp;#39;, &amp;#39;age&amp;#39;: 21, &amp;#39;city&amp;#39;: &amp;#39;Lima&amp;#39;}&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;update()&lt;/code&gt; to add new keys or overwrite existing keys from another dictionary or iterable of key-value pairs.&lt;/p&gt;
&lt;h2 id="what-update-does"&gt;What &lt;code&gt;update()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-update-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;update()&lt;/code&gt; modifies the original dictionary in place.&lt;/p&gt;</description></item><item><title>Python Dictionary values() Method</title><link>https://pythonbeginner.help/reference/python-dictionary-values-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-values-method/</guid><description>&lt;h1 id="python-dictionary-values-method"&gt;Python Dictionary &lt;code&gt;values()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python &lt;code&gt;dict.values()&lt;/code&gt; method returns all values from a dictionary.&lt;/p&gt;
&lt;p&gt;It is useful when you want the values only and do not need the keys. A common beginner use case is getting all values from a dictionary so you can print them, loop through them, or convert them to a list.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;student&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 class="s2"&gt;&amp;#34;age&amp;#34;&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="s2"&gt;&amp;#34;city&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Lima&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;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&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="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&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="n"&gt;dict_values&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Ana&amp;#39;&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="s1"&gt;&amp;#39;Lima&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;Ana&amp;#39;&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="s1"&gt;&amp;#39;Lima&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;&lt;code&gt;values()&lt;/code&gt; returns a dictionary view object. Convert it to a list if you want a regular list.&lt;/p&gt;</description></item><item><title>Python Dictionary: Creating a Dictionary</title><link>https://pythonbeginner.help/reference/python-dictionary-creating-a-dictionary/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dictionary-creating-a-dictionary/</guid><description>&lt;h1 id="python-dictionary-creating-a-dictionary"&gt;Python Dictionary: Creating a Dictionary&lt;/h1&gt;
&lt;p&gt;A dictionary in Python stores data as &lt;strong&gt;key-value pairs&lt;/strong&gt;. This page shows the main ways to create a dictionary, the basic syntax, and a few common beginner mistakes to avoid.&lt;/p&gt;
&lt;p&gt;If you are new to dictionaries, you may also want to read &lt;a href="https://pythonbeginner.help/learn/python-dictionaries-explained/"&gt;Python dictionaries explained&lt;/a&gt; or &lt;a href="https://pythonbeginner.help/glossary/what-is-a-dictionary-in-python/"&gt;what is a dictionary in Python&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;student&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 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 class="s2"&gt;&amp;#34;age&amp;#34;&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;is_active&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&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&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;student&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;
&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;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Ana&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&amp;#39;&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="s1"&gt;&amp;#39;is_active&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use curly braces with key-value pairs separated by commas. Keys and values are joined with a colon.&lt;/p&gt;</description></item><item><title>Python dir() Function Explained</title><link>https://pythonbeginner.help/reference/python-dir-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-dir-function-explained/</guid><description>&lt;h1 id="python-dir-function-explained"&gt;Python &lt;code&gt;dir()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The Python &lt;code&gt;dir()&lt;/code&gt; function is a simple inspection tool. It helps you see what names are available on an object, module, or in the current scope.&lt;/p&gt;
&lt;p&gt;This is especially useful when you are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;learning Python&lt;/li&gt;
&lt;li&gt;exploring a new object&lt;/li&gt;
&lt;li&gt;debugging an &lt;code&gt;AttributeError&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;checking what methods exist on a value&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In short, &lt;code&gt;dir()&lt;/code&gt; helps you answer the question: &lt;strong&gt;“What can I use here?”&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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="nb"&gt;dir&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;dir(object)&lt;/code&gt; to see the attributes and methods available on that object.&lt;/p&gt;</description></item><item><title>Python Download Files from a URL Example</title><link>https://pythonbeginner.help/examples/python-download-files-from-a-url-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-download-files-from-a-url-example/</guid><description>&lt;h1 id="python-download-files-from-a-url-example"&gt;Python Download Files from a URL Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to download a file from a URL in Python and save it on your computer.&lt;/p&gt;
&lt;p&gt;You will learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;download a file from a web address&lt;/li&gt;
&lt;li&gt;save it locally&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;requests.get()&lt;/code&gt; to fetch the file&lt;/li&gt;
&lt;li&gt;write the file safely with binary mode&lt;/li&gt;
&lt;li&gt;handle common problems like bad URLs and missing packages&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;requests&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;https://example.com/file.txt&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&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="n"&gt;url&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;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;raise_for_status&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;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;file.txt&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;wb&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;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Download complete&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 is the fastest working example. It downloads the file and saves it as &lt;code&gt;file.txt&lt;/code&gt; in the current folder.&lt;/p&gt;</description></item><item><title>Python Email Sender Script Example</title><link>https://pythonbeginner.help/examples/python-email-sender-script-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-email-sender-script-example/</guid><description>&lt;h1 id="python-email-sender-script-example"&gt;Python Email Sender Script Example&lt;/h1&gt;
&lt;p&gt;This example shows how to send an email in Python using the standard library.&lt;/p&gt;
&lt;p&gt;You will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to create a simple email message&lt;/li&gt;
&lt;li&gt;How to connect to an SMTP server&lt;/li&gt;
&lt;li&gt;How to log in and send the email&lt;/li&gt;
&lt;li&gt;Which values you must replace before the script works&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page focuses on a small working script. It also covers common setup problems that beginners often hit.&lt;/p&gt;</description></item><item><title>Python enumerate() Function Explained</title><link>https://pythonbeginner.help/reference/python-enumerate-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-enumerate-function-explained/</guid><description>&lt;h1 id="python-enumerate-function-explained"&gt;Python &lt;code&gt;enumerate()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;enumerate()&lt;/code&gt; is a built-in Python function that helps you loop through items while also keeping track of their position.&lt;/p&gt;
&lt;p&gt;It is useful when you need both:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the item itself&lt;/li&gt;
&lt;li&gt;its index in the loop&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Beginners often use a manual counter variable for this, but &lt;code&gt;enumerate()&lt;/code&gt; is usually cleaner and easier to read.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;enumerate&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;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&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="mi"&gt;0&lt;/span&gt; &lt;span class="n"&gt;red&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;green&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="n"&gt;blue&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;enumerate()&lt;/code&gt; when you need both the item and its position in a loop.&lt;/p&gt;</description></item><item><title>Python Error Handling Example Script</title><link>https://pythonbeginner.help/examples/python-error-handling-example-script/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-error-handling-example-script/</guid><description>&lt;h1 id="python-error-handling-example-script"&gt;Python Error Handling Example Script&lt;/h1&gt;
&lt;p&gt;This page shows a small, runnable Python script that uses &lt;code&gt;try&lt;/code&gt;, &lt;code&gt;except&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;, and &lt;code&gt;finally&lt;/code&gt; together.&lt;/p&gt;
&lt;p&gt;It is a practical example, not a theory page. The goal is to help you see what happens when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;code runs successfully&lt;/li&gt;
&lt;li&gt;code raises an error&lt;/li&gt;
&lt;li&gt;some final code should always run&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want a full explanation of the pattern itself, see &lt;a href="https://pythonbeginner.help/learn/using-try-except-else-and-finally-in-python/"&gt;using try, except, else, and finally in Python&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python Errors and Exceptions Explained</title><link>https://pythonbeginner.help/learn/python-errors-and-exceptions-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-errors-and-exceptions-explained/</guid><description>&lt;h1 id="python-errors-and-exceptions-explained"&gt;Python Errors and Exceptions Explained&lt;/h1&gt;
&lt;p&gt;Python errors and exceptions are messages that tell you something went wrong in your code. As a beginner, these messages can look confusing at first, but they are actually very useful.&lt;/p&gt;
&lt;p&gt;This page explains:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what errors and exceptions are&lt;/li&gt;
&lt;li&gt;how Python behaves when it finds a problem&lt;/li&gt;
&lt;li&gt;how to read a traceback&lt;/li&gt;
&lt;li&gt;when to handle an exception with &lt;code&gt;try&lt;/code&gt; and &lt;code&gt;except&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;when you should fix the code instead&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once you can read what Python is telling you, those scary red messages turn into a map that points straight at the problem.&lt;/p&gt;</description></item><item><title>Python File Backup Script Example</title><link>https://pythonbeginner.help/examples/python-file-backup-script-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-file-backup-script-example/</guid><description>&lt;h1 id="python-file-backup-script-example"&gt;Python File Backup Script Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to create a simple Python file backup script.&lt;/p&gt;
&lt;p&gt;The goal is small and practical:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;copy one file to a backup file&lt;/li&gt;
&lt;li&gt;check that the original file exists first&lt;/li&gt;
&lt;li&gt;print a clear message about what happened&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a good first project if you are learning how Python works with files and paths.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use this as the fastest working version:&lt;/p&gt;</description></item><item><title>Python File Handling Basics (Read and Write)</title><link>https://pythonbeginner.help/learn/python-file-handling-basics-read-and-write/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-file-handling-basics-read-and-write/</guid><description>&lt;h1 id="python-file-handling-basics-read-and-write"&gt;Python File Handling Basics (Read and Write)&lt;/h1&gt;
&lt;p&gt;File handling in Python means working with files saved on your computer.&lt;/p&gt;
&lt;p&gt;At the beginner level, this usually means:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;opening a file&lt;/li&gt;
&lt;li&gt;reading data from it&lt;/li&gt;
&lt;li&gt;writing data to it&lt;/li&gt;
&lt;li&gt;closing it safely&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Python makes this simple with the built-in &lt;code&gt;open()&lt;/code&gt; function. This page focuses on the core ideas only. If you need a specific task, such as reading line by line or checking whether a file exists, use the related guides in the &lt;strong&gt;See also&lt;/strong&gt; section.&lt;/p&gt;</description></item><item><title>Python File Organizer Script Example</title><link>https://pythonbeginner.help/examples/python-file-organizer-script-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-file-organizer-script-example/</guid><description>&lt;h1 id="python-file-organizer-script-example"&gt;Python File Organizer Script Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to organize files in a folder by moving them into subfolders based on file type.&lt;/p&gt;
&lt;p&gt;The goal of this page is to help you understand one practical Python script. It is not a full guide to every file-handling function in Python.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;from&lt;/span&gt; &lt;span class="nn"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;
&lt;/span&gt;&lt;/span&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;shutil&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;source_folder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;downloads&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="n"&gt;folders&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 class="s2"&gt;&amp;#34;.jpg&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;images&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="s2"&gt;&amp;#34;.png&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;images&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="s2"&gt;&amp;#34;.gif&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;images&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="s2"&gt;&amp;#34;.txt&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;text_files&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="s2"&gt;&amp;#34;.pdf&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;pdf_files&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="s2"&gt;&amp;#34;.csv&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;csv_files&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="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;source_folder&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iterdir&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;item&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_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;extension&lt;/span&gt; &lt;span class="o"&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;suffix&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="n"&gt;folder_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;folders&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="n"&gt;extension&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;other&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;destination_folder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;source_folder&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;folder_name&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;destination_folder&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exist_ok&lt;/span&gt;&lt;span class="o"&gt;=&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="n"&gt;shutil&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;move&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;item&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;destination_folder&lt;/span&gt; &lt;span class="o"&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;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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Files organized.&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 example organizes files inside a folder named &lt;code&gt;downloads&lt;/code&gt;. It groups files by extension and puts unknown file types into an &lt;code&gt;other&lt;/code&gt; folder.&lt;/p&gt;</description></item><item><title>Python Filter Data from a List Example</title><link>https://pythonbeginner.help/examples/python-filter-data-from-a-list-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-filter-data-from-a-list-example/</guid><description>&lt;h1 id="python-filter-data-from-a-list-example"&gt;Python Filter Data from a List Example&lt;/h1&gt;
&lt;p&gt;Filtering a list means creating a new list that keeps only the items you want.&lt;/p&gt;
&lt;p&gt;This example shows simple beginner-friendly ways to filter data from a Python list using:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a &lt;code&gt;for&lt;/code&gt; loop&lt;/li&gt;
&lt;li&gt;an &lt;code&gt;if&lt;/code&gt; statement&lt;/li&gt;
&lt;li&gt;a list comprehension&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are new to loops and conditions, this is a good place to start before reading more detailed guides on &lt;a href="https://pythonbeginner.help/learn/python-for-loops-explained/"&gt;Python &lt;code&gt;for&lt;/code&gt; loops&lt;/a&gt; and &lt;a href="https://pythonbeginner.help/learn/python-if-statements-explained/"&gt;Python &lt;code&gt;if&lt;/code&gt; statements&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python filter() Function Explained</title><link>https://pythonbeginner.help/reference/python-filter-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-filter-function-explained/</guid><description>&lt;h1 id="python-filter-function-explained"&gt;Python &lt;code&gt;filter()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;filter()&lt;/code&gt; is used to keep only the items that pass a test.&lt;/p&gt;
&lt;p&gt;It takes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a function that checks each item&lt;/li&gt;
&lt;li&gt;an iterable such as a list, tuple, or string&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The result is &lt;strong&gt;not a list&lt;/strong&gt; in Python 3. It returns a &lt;code&gt;filter&lt;/code&gt; object, so beginners often convert it with &lt;code&gt;list()&lt;/code&gt; to see the values.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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 class="mi"&gt;4&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 class="mi"&gt;6&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="nb"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&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 class="n"&gt;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="nb"&gt;list&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 class="c1"&gt;# [2, 4, 6]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;filter()&lt;/code&gt; returns a filter object, so beginners often wrap it with &lt;code&gt;list()&lt;/code&gt; to see the results.&lt;/p&gt;</description></item><item><title>Python float() Function Explained</title><link>https://pythonbeginner.help/reference/python-float-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-float-function-explained/</guid><description>&lt;h1 id="python-float-function-explained"&gt;Python float() Function Explained&lt;/h1&gt;
&lt;p&gt;The built-in &lt;code&gt;float()&lt;/code&gt; function converts a value into a floating-point number.&lt;/p&gt;
&lt;p&gt;This is useful when you need decimal numbers in Python, especially when working with user input, file data, or numeric strings. In this guide, you will learn what &lt;code&gt;float()&lt;/code&gt; does, what values it accepts, what errors it can raise, and how to use it safely.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;float&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;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;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;3.14&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="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;</description></item><item><title>Python Folder Size Calculator Example</title><link>https://pythonbeginner.help/examples/python-folder-size-calculator-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-folder-size-calculator-example/</guid><description>&lt;h1 id="python-folder-size-calculator-example"&gt;Python Folder Size Calculator Example&lt;/h1&gt;
&lt;p&gt;Build a simple Python script that calculates the total size of files inside a folder. This example helps beginners practice working with file paths, loops, and the &lt;code&gt;os&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;If you want the shortest working version first, start here:&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;folder_path&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="n"&gt;total_size&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;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="ow"&gt;in&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;folder_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="n"&gt;path&lt;/span&gt; &lt;span class="o"&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;path&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="n"&gt;folder_path&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="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;isfile&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="n"&gt;total_size&lt;/span&gt; &lt;span class="o"&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;path&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getsize&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&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;Total size: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total_size&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; bytes&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 quick version adds the size of files in one folder only. A later section expands it to include subfolders.&lt;/p&gt;</description></item><item><title>Python for Loops Explained</title><link>https://pythonbeginner.help/learn/python-for-loops-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-for-loops-explained/</guid><description>&lt;h1 id="python-for-loops-explained"&gt;Python for Loops Explained&lt;/h1&gt;
&lt;p&gt;A &lt;code&gt;for&lt;/code&gt; loop in Python lets you repeat code once for each item in a group of values. It is one of the most useful tools for beginners because it makes it easy to work through lists, strings, dictionaries, and &lt;code&gt;range()&lt;/code&gt; values without manually managing positions.&lt;/p&gt;
&lt;p&gt;You will use &lt;code&gt;for&lt;/code&gt; loops when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;print each item in a list&lt;/li&gt;
&lt;li&gt;process each character in a string&lt;/li&gt;
&lt;li&gt;repeat something a fixed number of times&lt;/li&gt;
&lt;li&gt;go through dictionary data one piece at a time&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;fruits&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;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;cherry&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;fruit&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fruits&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;fruit&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>Python Functions Explained</title><link>https://pythonbeginner.help/learn/python-functions-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-functions-explained/</guid><description>&lt;h1 id="python-functions-explained"&gt;Python Functions Explained&lt;/h1&gt;
&lt;p&gt;Functions are one of the most useful parts of Python.&lt;/p&gt;
&lt;p&gt;A function is a named block of code that does a specific job. You define it once, then call it whenever you need it. This helps you avoid repeating the same code and makes programs easier to read.&lt;/p&gt;
&lt;p&gt;In this guide, you will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what a function is&lt;/li&gt;
&lt;li&gt;why functions are useful&lt;/li&gt;
&lt;li&gt;how to define and call a function&lt;/li&gt;
&lt;li&gt;how parameters work at a basic level&lt;/li&gt;
&lt;li&gt;how return values work&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want a shorter definition first, see &lt;a href="https://pythonbeginner.help/glossary/what-is-a-function-in-python/"&gt;what is a function in Python&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python Generate Random Numbers Example</title><link>https://pythonbeginner.help/examples/python-generate-random-numbers-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-generate-random-numbers-example/</guid><description>&lt;h1 id="python-generate-random-numbers-example"&gt;Python Generate Random Numbers Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to generate random numbers in Python with the &lt;code&gt;random&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;You will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to import the &lt;code&gt;random&lt;/code&gt; module&lt;/li&gt;
&lt;li&gt;How to generate one random integer&lt;/li&gt;
&lt;li&gt;How to generate several random numbers in a loop&lt;/li&gt;
&lt;li&gt;How &lt;code&gt;randint()&lt;/code&gt; differs from other random functions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want the shortest working example, start here:&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;random&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;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;randint&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;10&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;random.randint(start, end)&lt;/code&gt; to get a random integer between both numbers, including the endpoints.&lt;/p&gt;</description></item><item><title>Python Hello World Example Explained</title><link>https://pythonbeginner.help/examples/python-hello-world-example-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-hello-world-example-explained/</guid><description>&lt;h1 id="python-hello-world-example-explained"&gt;Python Hello World Example Explained&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows the simplest useful Python program. You will learn what it does, how to run it, and how to fix a few common mistakes.&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Hello, world!&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;Save this in a &lt;code&gt;.py&lt;/code&gt; file or run it in the Python interpreter to see your first working Python output.&lt;/p&gt;
&lt;h2 id="what-this-example-shows"&gt;What this example shows &lt;a class="heading-anchor" href="#what-this-example-shows" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This example teaches a few important basics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The smallest useful Python program&lt;/li&gt;
&lt;li&gt;How to display text on the screen&lt;/li&gt;
&lt;li&gt;How Python runs code from top to bottom&lt;/li&gt;
&lt;li&gt;Why this is often the first program beginners write&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even though it is only one line long, it introduces an important idea: Python can execute your code and produce visible output right away.&lt;/p&gt;</description></item><item><title>Python help() Function Explained</title><link>https://pythonbeginner.help/reference/python-help-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-help-function-explained/</guid><description>&lt;h1 id="python-help-function-explained"&gt;Python help() Function Explained&lt;/h1&gt;
&lt;p&gt;Python’s &lt;code&gt;help()&lt;/code&gt; function shows built-in documentation inside Python.&lt;/p&gt;
&lt;p&gt;It is useful when you want to quickly inspect a function, class, method, or module without leaving the Python shell. For beginners, it is a simple way to check what something does, what arguments it accepts, and how it is meant to be used.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;help&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&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;help&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="n"&gt;help&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;modules&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;Use &lt;code&gt;help()&lt;/code&gt; to view built-in documentation in the Python shell. Pass an object like &lt;code&gt;len&lt;/code&gt; or &lt;code&gt;str&lt;/code&gt;, or use a string such as &lt;code&gt;'modules'&lt;/code&gt; for special interactive help topics.&lt;/p&gt;</description></item><item><title>Python id() Function Explained</title><link>https://pythonbeginner.help/reference/python-id-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-id-function-explained/</guid><description>&lt;h1 id="python-id-function-explained"&gt;Python &lt;code&gt;id()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The Python &lt;code&gt;id()&lt;/code&gt; function returns a number that identifies an object while that object exists.&lt;/p&gt;
&lt;p&gt;Beginners usually see &lt;code&gt;id()&lt;/code&gt; when learning how variables and objects work in Python. It can help you understand whether two variables point to the same object, especially with mutable objects like lists and dictionaries.&lt;/p&gt;
&lt;p&gt;Use &lt;code&gt;id()&lt;/code&gt; for inspection and debugging. Do &lt;strong&gt;not&lt;/strong&gt; use it to compare normal values. For value comparison, use &lt;code&gt;==&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Python if Statements Explained</title><link>https://pythonbeginner.help/learn/python-if-statements-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-if-statements-explained/</guid><description>&lt;h1 id="python-if-statements-explained"&gt;Python if Statements Explained&lt;/h1&gt;
&lt;p&gt;An &lt;code&gt;if&lt;/code&gt; statement lets Python make a decision.&lt;/p&gt;
&lt;p&gt;It checks a condition. If that condition is &lt;code&gt;True&lt;/code&gt;, Python runs the indented code underneath it. If the condition is &lt;code&gt;False&lt;/code&gt;, Python skips that code.&lt;/p&gt;
&lt;p&gt;This is one of the most important tools in Python because it controls the flow of your program.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s walk through how an &lt;code&gt;if&lt;/code&gt; statement is written, how Python evaluates the condition, and the small mistakes that trip up most beginners.&lt;/p&gt;</description></item><item><title>Python if-else and elif Explained</title><link>https://pythonbeginner.help/learn/python-if-else-and-elif-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-if-else-and-elif-explained/</guid><description>&lt;h1 id="python-if-else-and-elif-explained"&gt;Python if-else and elif Explained&lt;/h1&gt;
&lt;p&gt;Learn how Python chooses between different code paths using &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, and &lt;code&gt;else&lt;/code&gt;. This page helps beginners read and write basic conditional logic with clear examples.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;13&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;child&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;elif&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&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;teen&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;adult&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;figure class="diagram" role="group" aria-label="Python runs only the first branch whose condition is True."&gt;
&lt;svg width="483" height="262" viewBox="0 0 483 262" class="d-svg" xmlns="http://www.w3.org/2000/svg" role="img"&gt;
 &lt;defs&gt;&lt;marker id="flowarrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"&gt;&lt;path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/&gt;&lt;/marker&gt;&lt;/defs&gt;&lt;line x1="150" y1="6" x2="150" y2="2" class="d-edge"/&gt;&lt;polygon points="150,2 270,36 150,70 30,36" class="d-decision"/&gt;
 &lt;text x="150" y="36" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;age &amp;lt; 13&lt;/text&gt;&lt;line x1="270" y1="36" x2="316" y2="36" class="d-edge" marker-end="url(#flowarrow)"/&gt;
 &lt;text x="284" y="28" class="d-edge-label"&gt;True&lt;/text&gt;
 &lt;rect x="316" y="15" width="151" height="42" rx="8" class="d-node"/&gt;
 &lt;text x="391" y="36" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;print(&amp;#39;child&amp;#39;)&lt;/text&gt;&lt;line x1="150" y1="70" x2="150" y2="106" class="d-edge" marker-end="url(#flowarrow)"/&gt;
 &lt;text x="158" y="88" class="d-edge-label"&gt;False&lt;/text&gt;&lt;polygon points="150,106 270,140 150,174 30,140" class="d-decision"/&gt;
 &lt;text x="150" y="140" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;age &amp;lt; 18&lt;/text&gt;&lt;line x1="270" y1="140" x2="316" y2="140" class="d-edge" marker-end="url(#flowarrow)"/&gt;
 &lt;text x="284" y="132" class="d-edge-label"&gt;True&lt;/text&gt;
 &lt;rect x="316" y="119" width="151" height="42" rx="8" class="d-node"/&gt;
 &lt;text x="391" y="140" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;print(&amp;#39;teen&amp;#39;)&lt;/text&gt;&lt;line x1="150" y1="174" x2="150" y2="208" class="d-edge" marker-end="url(#flowarrow)"/&gt;
 &lt;text x="158" y="192" class="d-edge-label"&gt;False&lt;/text&gt;&lt;rect x="75" y="208" width="151" height="42" rx="8" class="d-node"/&gt;
 &lt;text x="150" y="229" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;print(&amp;#39;adult&amp;#39;)&lt;/text&gt;&lt;/svg&gt;&lt;figcaption&gt;Python runs only the first branch whose condition is True.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Use &lt;code&gt;if&lt;/code&gt; for the first condition, &lt;code&gt;elif&lt;/code&gt; for extra conditions, and &lt;code&gt;else&lt;/code&gt; for the fallback case.&lt;/p&gt;</description></item><item><title>Python Indentation Rules and Why They Matter</title><link>https://pythonbeginner.help/learn/python-indentation-rules-and-why-they-matter/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-indentation-rules-and-why-they-matter/</guid><description>&lt;h1 id="python-indentation-rules-and-why-they-matter"&gt;Python Indentation Rules and Why They Matter&lt;/h1&gt;
&lt;p&gt;Indentation in Python means the spaces at the beginning of a line.&lt;/p&gt;
&lt;p&gt;In many programming languages, blocks of code are grouped with braces like &lt;code&gt;{}&lt;/code&gt;. Python works differently. It uses indentation to show which lines belong together.&lt;/p&gt;
&lt;p&gt;This is why indentation is not just a style choice in Python. It is part of the language syntax.&lt;/p&gt;
&lt;p&gt;If you are learning Python syntax, indentation is one of the first things to understand. It affects &lt;code&gt;if&lt;/code&gt; statements, loops, functions, classes, and error handling blocks.&lt;/p&gt;</description></item><item><title>Python Inheritance Example</title><link>https://pythonbeginner.help/examples/python-inheritance-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-inheritance-example/</guid><description>&lt;h1 id="python-inheritance-example"&gt;Python Inheritance Example&lt;/h1&gt;
&lt;p&gt;Inheritance is a way to reuse code in Python classes. In this example, a child class inherits from a parent class and can use the parent class method while also adding its own method.&lt;/p&gt;
&lt;p&gt;This page gives you a simple, beginner-friendly example so you can see how inheritance works in real code.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&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;def&lt;/span&gt; &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&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;Animal sound&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;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Animal&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;def&lt;/span&gt; &lt;span class="nf"&gt;bark&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&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;Woof!&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="n"&gt;dog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Dog&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;dog&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;speak&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;dog&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bark&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>Python input() Function Explained</title><link>https://pythonbeginner.help/reference/python-input-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-input-function-explained/</guid><description>&lt;h1 id="python-input-function-explained"&gt;Python &lt;code&gt;input()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;input()&lt;/code&gt; function lets your Python program receive text from the user.&lt;/p&gt;
&lt;p&gt;It is one of the most common beginner tools in Python because it makes programs interactive. You can use it to ask for a name, an age, a number, or any other value the user types.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Enter your name: &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="s2"&gt;&amp;#34;Hello, &amp;#34;&lt;/span&gt; &lt;span class="o"&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;input()&lt;/code&gt; to get text from the user. It always returns a string.&lt;/p&gt;</description></item><item><title>Python int() Function Explained</title><link>https://pythonbeginner.help/reference/python-int-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-int-function-explained/</guid><description>&lt;h1 id="python-int-function-explained"&gt;Python &lt;code&gt;int()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The Python &lt;code&gt;int()&lt;/code&gt; function converts a value into an integer.&lt;/p&gt;
&lt;p&gt;Beginners often use &lt;code&gt;int()&lt;/code&gt; when they want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;turn text like &lt;code&gt;&amp;quot;42&amp;quot;&lt;/code&gt; into the number &lt;code&gt;42&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;convert user input into a whole number&lt;/li&gt;
&lt;li&gt;remove the decimal part from a float&lt;/li&gt;
&lt;li&gt;read numbers written in binary or hexadecimal&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is a built-in function, so you can use it directly without importing anything.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="nb"&gt;print&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="s2"&gt;&amp;#34;42&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="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.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 class="nb"&gt;print&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="s2"&gt;&amp;#34;101&amp;#34;&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;</description></item><item><title>Python isinstance() Function Explained</title><link>https://pythonbeginner.help/reference/python-isinstance-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-isinstance-function-explained/</guid><description>&lt;h1 id="python-isinstance-function-explained"&gt;Python &lt;code&gt;isinstance()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;isinstance()&lt;/code&gt; checks whether a value matches a type.&lt;/p&gt;
&lt;p&gt;It is a built-in Python function that returns either &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;. It is often used before running code that depends on a value being a string, number, list, tuple, or dictionary.&lt;/p&gt;
&lt;p&gt;In many cases, &lt;code&gt;isinstance()&lt;/code&gt; is a better choice than checking &lt;code&gt;type()&lt;/code&gt; directly because it also works with parent and child types.&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="n"&gt;value&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&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;int&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# True&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;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 class="c1"&gt;# False&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;isinstance(object, classinfo)&lt;/code&gt; to check whether a value matches a type or one of its parent types.&lt;/p&gt;</description></item><item><title>Python json Module Overview</title><link>https://pythonbeginner.help/standard-library/python-json-module-overview/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/python-json-module-overview/</guid><description>&lt;h1 id="python-json-module-overview"&gt;Python json Module Overview&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;json&lt;/code&gt; module is Python’s built-in tool for working with JSON data.&lt;/p&gt;
&lt;p&gt;Use it when you need to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read JSON text into Python&lt;/li&gt;
&lt;li&gt;Convert Python data into JSON&lt;/li&gt;
&lt;li&gt;Work with JSON files&lt;/li&gt;
&lt;li&gt;Send or receive structured data in APIs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;JSON is one of the most common data formats in programming, so learning the basic &lt;code&gt;json&lt;/code&gt; functions is very useful.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;json&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;person&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 class="s2"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&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;json_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_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="n"&gt;back_to_dict&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_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;back_to_dict&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&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>Python JSON Parser Example</title><link>https://pythonbeginner.help/examples/python-json-parser-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-json-parser-example/</guid><description>&lt;h1 id="python-json-parser-example"&gt;Python JSON Parser Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to parse JSON in Python and turn it into normal Python data.&lt;/p&gt;
&lt;p&gt;You will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;how to import the &lt;code&gt;json&lt;/code&gt; module&lt;/li&gt;
&lt;li&gt;how to parse a JSON string with &lt;code&gt;json.loads()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;how JSON becomes Python data types&lt;/li&gt;
&lt;li&gt;how to read values from the parsed result safely&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want the shortest working example first, start here:&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;json&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;json_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;{&amp;#34;name&amp;#34;: &amp;#34;Alice&amp;#34;, &amp;#34;age&amp;#34;: 25, &amp;#34;skills&amp;#34;: [&amp;#34;Python&amp;#34;, &amp;#34;SQL&amp;#34;]}&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="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_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="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&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;name&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;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;skills&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&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Use &lt;code&gt;json.loads()&lt;/code&gt; for a JSON string. Use &lt;code&gt;json.load()&lt;/code&gt; when reading JSON from a file.&lt;/p&gt;</description></item><item><title>Python JSON to Dictionary Example</title><link>https://pythonbeginner.help/examples/python-json-to-dictionary-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-json-to-dictionary-example/</guid><description>&lt;h1 id="python-json-to-dictionary-example"&gt;Python JSON to Dictionary Example&lt;/h1&gt;
&lt;p&gt;If you have JSON text and want to turn it into normal Python data, the usual tool is the built-in &lt;code&gt;json&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;This example shows one practical task: converting a JSON string into a Python dictionary so you can read values by key and use them in your program.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;json&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;json_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;{&amp;#34;name&amp;#34;: &amp;#34;Alice&amp;#34;, &amp;#34;age&amp;#34;: 25, &amp;#34;is_admin&amp;#34;: false}&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&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="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_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="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&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;type&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&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;name&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;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>Python Keywords Explained (Beginner Guide)</title><link>https://pythonbeginner.help/learn/python-keywords-explained-beginner-guide/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-keywords-explained-beginner-guide/</guid><description>&lt;h1 id="python-keywords-explained-beginner-guide"&gt;Python Keywords Explained (Beginner Guide)&lt;/h1&gt;
&lt;p&gt;Python keywords are reserved words that have a special meaning in the language.&lt;/p&gt;
&lt;p&gt;They matter because Python uses them to understand the structure of your code. If you use a keyword in the wrong place, you will usually get a syntax error. As a beginner, learning to recognize keywords will make Python code much easier to read.&lt;/p&gt;
&lt;p&gt;You do &lt;strong&gt;not&lt;/strong&gt; need to memorize every keyword right away. Start by understanding what keywords are, what they do, and how to avoid using them as names.&lt;/p&gt;</description></item><item><title>Python len() Function Explained</title><link>https://pythonbeginner.help/reference/python-len-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-len-function-explained/</guid><description>&lt;h1 id="python-len-function-explained"&gt;Python len() Function Explained&lt;/h1&gt;
&lt;p&gt;The built-in &lt;code&gt;len()&lt;/code&gt; function returns the size of an object.&lt;/p&gt;
&lt;p&gt;Beginners often use &lt;code&gt;len()&lt;/code&gt; to count:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;characters in a string&lt;/li&gt;
&lt;li&gt;items in a list or tuple&lt;/li&gt;
&lt;li&gt;keys in a dictionary&lt;/li&gt;
&lt;li&gt;unique items in a set&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is a simple but very useful function. You will use it often when checking if something is empty, validating input, or counting stored values safely.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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="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="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&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;len&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 class="c1"&gt;# 5&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;len&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 class="c1"&gt;# 3&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;len()&lt;/code&gt; to get the number of characters in a string or the number of items in a container like a list, tuple, set, or dictionary.&lt;/p&gt;</description></item><item><title>Python List append() Method</title><link>https://pythonbeginner.help/reference/python-list-append-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-append-method/</guid><description>&lt;h1 id="python-list-append-method"&gt;Python List append() Method&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;append()&lt;/code&gt; method adds &lt;strong&gt;one item&lt;/strong&gt; to the &lt;strong&gt;end&lt;/strong&gt; of a Python list.&lt;/p&gt;
&lt;p&gt;Use it when you want to grow a list step by step. This method changes the original list directly, so it does &lt;strong&gt;not&lt;/strong&gt; create a new list.&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="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="n"&gt;numbers&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="mi"&gt;4&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# [1, 2, 3, 4]&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;append()&lt;/code&gt; to add one item to the end of a list. It changes the original list.&lt;/p&gt;</description></item><item><title>Python List clear() Method</title><link>https://pythonbeginner.help/reference/python-list-clear-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-clear-method/</guid><description>&lt;h1 id="python-list-clear-method"&gt;Python List &lt;code&gt;clear()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;list.clear()&lt;/code&gt; removes every item from a list.&lt;/p&gt;
&lt;p&gt;Use it when you want to empty an existing list &lt;strong&gt;in place&lt;/strong&gt;. This is useful when you want to keep using the same list object, but remove all of its contents.&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="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="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="n"&gt;items&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clear&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;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&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;clear()&lt;/code&gt; to remove all items from an existing list in place.&lt;/p&gt;
&lt;h2 id="what-listclear-does"&gt;What &lt;code&gt;list.clear()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-listclear-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;list.clear()&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>Python List copy() Method</title><link>https://pythonbeginner.help/reference/python-list-copy-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-copy-method/</guid><description>&lt;h1 id="python-list-copy-method"&gt;Python List &lt;code&gt;copy()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;list.copy()&lt;/code&gt; creates a new list with the same items as an existing list.&lt;/p&gt;
&lt;p&gt;This method is useful when you want to work with a list without changing the original one. It is especially important for beginners because using &lt;code&gt;=&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; make a real copy.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="n"&gt;new_numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;copy&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;new_numbers&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="mi"&gt;4&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="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="c1"&gt;# [1, 2, 3]&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;new_numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# [1, 2, 3, 4]&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;list.copy()&lt;/code&gt; when you want a new list object with the same items. This is a &lt;strong&gt;shallow copy&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Python List count() Method</title><link>https://pythonbeginner.help/reference/python-list-count-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-count-method/</guid><description>&lt;h1 id="python-list-count-method"&gt;Python List &lt;code&gt;count()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;list.count()&lt;/code&gt; tells you how many times one value appears in a list.&lt;/p&gt;
&lt;p&gt;It is a useful method when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;count one specific item&lt;/li&gt;
&lt;li&gt;check whether a value appears more than once&lt;/li&gt;
&lt;li&gt;quickly see how many matches exist&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It returns a number and does not change the original list.&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="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;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 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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&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="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 class="c1"&gt;# 3&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;list.count(value)&lt;/code&gt; to count how many times one value appears in a list.&lt;/p&gt;</description></item><item><title>Python List extend() Method</title><link>https://pythonbeginner.help/reference/python-list-extend-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-extend-method/</guid><description>&lt;h1 id="python-list-extend-method"&gt;Python List &lt;code&gt;extend()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;list.extend()&lt;/code&gt; adds items from another iterable to the end of a list.&lt;/p&gt;
&lt;p&gt;It changes the original list in place, which means it updates the same list instead of creating a new one. This method is useful when you want to add multiple values at once.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;more_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;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&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;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;more_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;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="c1"&gt;# [1, 2, 3, 4]&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;extend()&lt;/code&gt; when you want to add each item from another iterable into the same list.&lt;/p&gt;</description></item><item><title>Python List index() Method</title><link>https://pythonbeginner.help/reference/python-list-index-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-index-method/</guid><description>&lt;h1 id="python-list-index-method"&gt;Python List &lt;code&gt;index()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;list.index()&lt;/code&gt; finds the position of a value in a list.&lt;/p&gt;
&lt;p&gt;Use it when you have a list and want to know where a specific item appears. It returns the index of the &lt;strong&gt;first matching item&lt;/strong&gt;. If the value is not in the list, Python raises a &lt;code&gt;ValueError&lt;/code&gt;.&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="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;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;cherry&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;position&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;banana&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;position&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 1&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;list.index(value)&lt;/code&gt; to get the position of the first matching item. It raises &lt;code&gt;ValueError&lt;/code&gt; if the item is not found.&lt;/p&gt;</description></item><item><title>Python List insert() Method</title><link>https://pythonbeginner.help/reference/python-list-insert-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-insert-method/</guid><description>&lt;h1 id="python-list-insert-method"&gt;Python List &lt;code&gt;insert()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;list.insert()&lt;/code&gt; adds an item to a list at a specific position.&lt;/p&gt;
&lt;p&gt;This method is useful when the position matters. For example, you may want to add a new value at the beginning of a list, in the middle, or just before the last item.&lt;/p&gt;
&lt;p&gt;Use &lt;code&gt;insert()&lt;/code&gt; when you need to place an item at a chosen index. If you only want to add an item at the end, see the &lt;a href="https://pythonbeginner.help/reference/python-list-append-method/"&gt;Python list &lt;code&gt;append()&lt;/code&gt; method&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python List Length (len)</title><link>https://pythonbeginner.help/reference/python-list-length-len/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-length-len/</guid><description>&lt;h1 id="python-list-length-len"&gt;Python List Length (&lt;code&gt;len&lt;/code&gt;)&lt;/h1&gt;
&lt;p&gt;Learn how to get the number of items in a Python list using &lt;code&gt;len()&lt;/code&gt;. This page focuses on the basic use of &lt;code&gt;len()&lt;/code&gt; with lists, common beginner mistakes, and simple examples.&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;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;count&lt;/span&gt; &lt;span class="o"&gt;=&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;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;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;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="mi"&gt;3&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;len(list_name)&lt;/code&gt; to get how many items are in a list.&lt;/p&gt;
&lt;h2 id="what-this-page-covers"&gt;What this page covers &lt;a class="heading-anchor" href="#what-this-page-covers" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;How &lt;code&gt;len()&lt;/code&gt; works with Python lists&lt;/li&gt;
&lt;li&gt;What value &lt;code&gt;len()&lt;/code&gt; returns&lt;/li&gt;
&lt;li&gt;Simple examples with empty and non-empty lists&lt;/li&gt;
&lt;li&gt;Common mistakes beginners make&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="what-len-returns-for-a-list"&gt;What &lt;code&gt;len()&lt;/code&gt; returns for a list &lt;a class="heading-anchor" href="#what-len-returns-for-a-list" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;len(my_list)&lt;/code&gt; returns an integer.&lt;/p&gt;</description></item><item><title>Python List pop() Method</title><link>https://pythonbeginner.help/reference/python-list-pop-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-pop-method/</guid><description>&lt;h1 id="python-list-pop-method"&gt;Python List pop() Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;list.pop()&lt;/code&gt; removes an item from a list and returns it.&lt;/p&gt;
&lt;p&gt;This method is useful when you want to both:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;delete an item from a list&lt;/li&gt;
&lt;li&gt;keep the removed value for later use&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you do not pass an index, &lt;code&gt;pop()&lt;/code&gt; removes the last item. Beginners often confuse &lt;code&gt;pop()&lt;/code&gt; with &lt;a href="https://pythonbeginner.help/reference/python-list-remove-method/"&gt;&lt;code&gt;remove()&lt;/code&gt;&lt;/a&gt;, or expect it to create a new list instead of changing the original one.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;last_item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pop&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last_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 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&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;</description></item><item><title>Python List Processing Example</title><link>https://pythonbeginner.help/examples/python-list-processing-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-list-processing-example/</guid><description>&lt;h1 id="python-list-processing-example"&gt;Python List Processing Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to process a Python list step by step.&lt;/p&gt;
&lt;p&gt;You will learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;loop through a list&lt;/li&gt;
&lt;li&gt;filter items based on a condition&lt;/li&gt;
&lt;li&gt;create a new list with changed values&lt;/li&gt;
&lt;li&gt;summarize list data with functions like &lt;code&gt;sum()&lt;/code&gt; and &lt;code&gt;len()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The goal is to practice real list processing in one small script, without getting distracted by too much theory.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&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;8&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;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;# keep only even numbers&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;evens&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 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;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;if&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;2&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;evens&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="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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# make a new list with doubled values&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;doubled&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 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;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="n"&gt;doubled&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="n"&gt;n&lt;/span&gt; &lt;span class="o"&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;original:&amp;#34;&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&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;evens:&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;evens&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;doubled:&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;doubled&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;sum:&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sum&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&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use this as a simple list processing pattern: loop through the list, check each item, and build a new result list when needed.&lt;/p&gt;</description></item><item><title>Python List remove() Method</title><link>https://pythonbeginner.help/reference/python-list-remove-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-remove-method/</guid><description>&lt;h1 id="python-list-remove-method"&gt;Python List remove() Method&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;list.remove()&lt;/code&gt; method deletes the first item in a list that matches a given value.&lt;/p&gt;
&lt;p&gt;Use this method when you know the &lt;strong&gt;value&lt;/strong&gt; you want to remove, not the position. This page focuses on removing by value, not by index.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;orange&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;items&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;banana&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;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="c1"&gt;# [&amp;#39;apple&amp;#39;, &amp;#39;orange&amp;#39;]&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;remove(value)&lt;/code&gt; to delete the first matching item from a list.&lt;/p&gt;
&lt;h2 id="what-remove-does"&gt;What remove() does &lt;a class="heading-anchor" href="#what-remove-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;remove()&lt;/code&gt; is a list method that:&lt;/p&gt;</description></item><item><title>Python List reverse() Method</title><link>https://pythonbeginner.help/reference/python-list-reverse-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-reverse-method/</guid><description>&lt;h1 id="python-list-reverse-method"&gt;Python List &lt;code&gt;reverse()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;list.reverse()&lt;/code&gt; reverses the order of items in a list.&lt;/p&gt;
&lt;p&gt;It changes the original list in place, which means it does not create a new list. This is important because beginners often expect it to return a reversed copy.&lt;/p&gt;
&lt;p&gt;If you want to reverse a list, &lt;code&gt;reverse()&lt;/code&gt; is useful when changing the original list is okay. If you need a new list instead, use &lt;a href="https://pythonbeginner.help/reference/python-list-slicing-explained/"&gt;list slicing&lt;/a&gt; or another approach.&lt;/p&gt;</description></item><item><title>Python List Slicing Explained</title><link>https://pythonbeginner.help/reference/python-list-slicing-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-slicing-explained/</guid><description>&lt;h1 id="python-list-slicing-explained"&gt;Python List Slicing Explained&lt;/h1&gt;
&lt;p&gt;List slicing lets you get part of a list in Python. It is a very common pattern, and once you understand &lt;code&gt;start&lt;/code&gt;, &lt;code&gt;stop&lt;/code&gt;, and &lt;code&gt;step&lt;/code&gt;, it becomes much easier to read and write Python code.&lt;/p&gt;
&lt;p&gt;The basic slice form is:&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="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;step&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;You can leave out parts of the slice, and Python will use default values. One important rule to remember is that the &lt;code&gt;stop&lt;/code&gt; position is &lt;strong&gt;not included&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Python List sort() Method</title><link>https://pythonbeginner.help/reference/python-list-sort-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-sort-method/</guid><description>&lt;h1 id="python-list-sort-method"&gt;Python List &lt;code&gt;sort()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;list.sort()&lt;/code&gt; is the built-in list method for sorting items in a list.&lt;/p&gt;
&lt;p&gt;Use this page as a quick reference for what &lt;code&gt;sort()&lt;/code&gt; does, how its main arguments work, and the beginner mistakes to avoid.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;3&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;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sort&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="c1"&gt;# [1, 2, 3]&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;list.sort()&lt;/code&gt; to sort a list in place. It changes the original list and returns &lt;code&gt;None&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="what-listsort-does"&gt;What &lt;code&gt;list.sort()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-listsort-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;list.sort()&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>Python List: Creating a List</title><link>https://pythonbeginner.help/reference/python-list-creating-a-list/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-creating-a-list/</guid><description>&lt;h1 id="python-list-creating-a-list"&gt;Python List: Creating a List&lt;/h1&gt;
&lt;p&gt;A Python list is one of the most common data structures you will use. This page shows the main ways to create a list, what list syntax looks like, and when each approach is useful.&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="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="n"&gt;names&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;Ana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Ben&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Cara&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;empty_list&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 class="n"&gt;letters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;abc&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="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&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;names&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;empty_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;letters&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;
&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="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="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Ana&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Ben&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Cara&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&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;a&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;b&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;c&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;Use square brackets &lt;code&gt;[]&lt;/code&gt; for most lists. Use &lt;code&gt;list()&lt;/code&gt; when converting another iterable, such as a string, tuple, or &lt;code&gt;range()&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Python list() Function Explained</title><link>https://pythonbeginner.help/reference/python-list-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-list-function-explained/</guid><description>&lt;h1 id="python-list-function-explained"&gt;Python list() Function Explained&lt;/h1&gt;
&lt;p&gt;The built-in &lt;code&gt;list()&lt;/code&gt; function creates a new list.&lt;/p&gt;
&lt;p&gt;Beginners usually use &lt;code&gt;list()&lt;/code&gt; for two main reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;to make an empty list&lt;/li&gt;
&lt;li&gt;to convert another iterable, such as a tuple, string, &lt;code&gt;range&lt;/code&gt;, set, or dictionary, into a list&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page explains how &lt;code&gt;list()&lt;/code&gt; works, what it returns, and when you should use it.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="nb"&gt;list&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="n"&gt;letters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;abc&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="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&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;letters&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="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="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="s1"&gt;&amp;#39;b&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;c&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;Use &lt;code&gt;list()&lt;/code&gt; to create a list from another iterable such as a tuple, string, &lt;code&gt;range&lt;/code&gt;, set, or dictionary.&lt;/p&gt;</description></item><item><title>Python Lists Explained (Beginner Guide)</title><link>https://pythonbeginner.help/learn/python-lists-explained-beginner-guide/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-lists-explained-beginner-guide/</guid><description>&lt;h1 id="python-lists-explained-beginner-guide"&gt;Python Lists Explained (Beginner Guide)&lt;/h1&gt;
&lt;p&gt;A Python list is one of the most useful data types for beginners to learn.&lt;/p&gt;
&lt;p&gt;A list lets you store multiple values in one variable, keep them in order, and change them later. This makes lists a good choice when you need to work with groups of related data such as names, numbers, scores, file paths, or user input.&lt;/p&gt;
&lt;p&gt;This guide explains what a list is, how to create one, how to access and change items, and the most common things beginners do with lists.&lt;/p&gt;</description></item><item><title>Python Log File Analyzer Example</title><link>https://pythonbeginner.help/examples/python-log-file-analyzer-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-log-file-analyzer-example/</guid><description>&lt;h1 id="python-log-file-analyzer-example"&gt;Python Log File Analyzer Example&lt;/h1&gt;
&lt;p&gt;A log file analyzer is a good beginner project because it combines several useful Python skills in one script.&lt;/p&gt;
&lt;p&gt;In this example, you will read a log file, look for important lines such as &lt;code&gt;ERROR&lt;/code&gt;, &lt;code&gt;WARNING&lt;/code&gt;, and &lt;code&gt;INFO&lt;/code&gt;, count them, and print a simple summary.&lt;/p&gt;
&lt;p&gt;This page focuses on building one practical script. If you want a separate lesson on file handling, see &lt;a href="https://pythonbeginner.help/how-to/how-to-read-a-file-in-python/"&gt;how to read a file in Python&lt;/a&gt; or &lt;a href="https://pythonbeginner.help/how-to/how-to-read-a-file-line-by-line-in-python/"&gt;how to read a file line by line in Python&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python map() Function Explained</title><link>https://pythonbeginner.help/reference/python-map-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-map-function-explained/</guid><description>&lt;h1 id="python-map-function-explained"&gt;Python &lt;code&gt;map()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;Python’s &lt;code&gt;map()&lt;/code&gt; function applies the same function to each item in an iterable.&lt;/p&gt;
&lt;p&gt;This is useful when you want to transform data, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;converting numbers to strings&lt;/li&gt;
&lt;li&gt;changing strings to integers&lt;/li&gt;
&lt;li&gt;doubling every value in a list&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The main thing beginners need to know is this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;map()&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; return a list in Python 3&lt;/li&gt;
&lt;li&gt;it returns a &lt;strong&gt;map object&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;you often convert that result with &lt;code&gt;list()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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 class="mi"&gt;4&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="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;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="nb"&gt;list&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>Python math Module Overview</title><link>https://pythonbeginner.help/standard-library/python-math-module-overview/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/python-math-module-overview/</guid><description>&lt;h1 id="python-math-module-overview"&gt;Python math Module Overview&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;math&lt;/code&gt; module is a built-in Python module for common math work.&lt;/p&gt;
&lt;p&gt;It gives you extra functions and constants that are not available as basic language features. Beginners often use it for square roots, rounding, powers, and simple numeric calculations.&lt;/p&gt;
&lt;p&gt;This page is an overview. It shows what the module is, how to import it, and which parts are most useful to start with.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="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;25&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;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.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="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;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.8&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;pi&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;Expected output:&lt;/p&gt;</description></item><item><title>Python max() Function Explained</title><link>https://pythonbeginner.help/reference/python-max-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-max-function-explained/</guid><description>&lt;h1 id="python-max-function-explained"&gt;Python &lt;code&gt;max()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The built-in &lt;code&gt;max()&lt;/code&gt; function returns the largest item.&lt;/p&gt;
&lt;p&gt;You can use it in two main ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To get the largest item from an iterable like a list or tuple&lt;/li&gt;
&lt;li&gt;To compare two or more separate values&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is useful when you want the highest number, the alphabetically largest string, or the biggest item based on a custom rule.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&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;5&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="nb"&gt;max&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&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;max&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 class="mi"&gt;8&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;5&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="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;pear&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="nb"&gt;max&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;</description></item><item><title>Python Merge CSV Files Example</title><link>https://pythonbeginner.help/examples/python-merge-csv-files-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-merge-csv-files-example/</guid><description>&lt;h1 id="python-merge-csv-files-example"&gt;Python Merge CSV Files Example&lt;/h1&gt;
&lt;p&gt;If you have several CSV files with the same columns, you can combine them into one output file with a short Python script.&lt;/p&gt;
&lt;p&gt;This example shows a simple beginner-friendly way to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;read all &lt;code&gt;.csv&lt;/code&gt; files from one folder&lt;/li&gt;
&lt;li&gt;merge them into one file&lt;/li&gt;
&lt;li&gt;write the header row only once&lt;/li&gt;
&lt;li&gt;skip empty files safely&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It also helps you avoid common problems such as repeated headers, wrong file paths, and CSV encoding issues.&lt;/p&gt;</description></item><item><title>Python min() Function Explained</title><link>https://pythonbeginner.help/reference/python-min-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-min-function-explained/</guid><description>&lt;h1 id="python-min-function-explained"&gt;Python &lt;code&gt;min()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;min()&lt;/code&gt; is a built-in Python function that returns the smallest item. You can use it with a single iterable, like a list or tuple, or with multiple values separated by commas.&lt;/p&gt;
&lt;p&gt;This page explains what &lt;code&gt;min()&lt;/code&gt; does, its main syntax forms, and the common mistakes beginners make when using it.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;5&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;9&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 class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;min&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&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;min&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 class="mi"&gt;2&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 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;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="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="mi"&gt;1&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;min()&lt;/code&gt; with one iterable like a list, or with multiple values separated by commas.&lt;/p&gt;</description></item><item><title>Python Modules Explained</title><link>https://pythonbeginner.help/learn/python-modules-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-modules-explained/</guid><description>&lt;h1 id="python-modules-explained"&gt;Python Modules Explained&lt;/h1&gt;
&lt;p&gt;A Python module is one of the main ways Python keeps code organized and reusable.&lt;/p&gt;
&lt;p&gt;In simple terms, a module is usually a Python file that contains code such as variables, functions, or classes. You can then use that code in another Python file instead of writing it again.&lt;/p&gt;
&lt;p&gt;This page explains what modules are, why they matter, and how beginners use them. It keeps the focus on the idea of modules, not the full details of import syntax or packages.&lt;/p&gt;</description></item><item><title>Python Number Guessing Game Example</title><link>https://pythonbeginner.help/examples/python-number-guessing-game-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-number-guessing-game-example/</guid><description>&lt;h1 id="python-number-guessing-game-example"&gt;Python Number Guessing Game Example&lt;/h1&gt;
&lt;p&gt;A number guessing game is a great beginner project because it combines several core Python ideas in one small program.&lt;/p&gt;
&lt;p&gt;In this example, Python picks a random number, asks the user to guess it, and keeps running until the correct answer is entered. The goal here is not just to copy the code, but to understand how each part works.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This is the shortest working version:&lt;/p&gt;</description></item><item><title>Python Numbers Explained (int, float, complex)</title><link>https://pythonbeginner.help/learn/python-numbers-explained-int-float-complex/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-numbers-explained-int-float-complex/</guid><description>&lt;h1 id="python-numbers-explained-int-float-complex"&gt;Python Numbers Explained (int, float, complex)&lt;/h1&gt;
&lt;p&gt;Python has different number types for different kinds of values.&lt;/p&gt;
&lt;p&gt;The three main built-in numeric types are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;int&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;float&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;complex&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are just starting Python, you will use &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;float&lt;/code&gt; most of the time. This page explains what each type means, how to recognize it, and a few common mistakes beginners run into.&lt;/p&gt;
&lt;p&gt;Here is a tour of each numeric type, the basic math operations, and how to convert between them.&lt;/p&gt;</description></item><item><title>Python open() Function Explained</title><link>https://pythonbeginner.help/reference/python-open-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-open-function-explained/</guid><description>&lt;h1 id="python-open-function-explained"&gt;Python open() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;open()&lt;/code&gt; is the built-in Python function used to open a file so your program can read from it or write to it.&lt;/p&gt;
&lt;p&gt;This page is a beginner-friendly reference for &lt;code&gt;open()&lt;/code&gt;. You will learn what it does, the most common arguments, what it returns, and how to use it safely when working with files.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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;example.txt&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;r&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;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&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;content&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;with&lt;/code&gt; so the file closes automatically. &lt;code&gt;&amp;quot;r&amp;quot;&lt;/code&gt; means read mode.&lt;/p&gt;</description></item><item><title>Python os Module Overview</title><link>https://pythonbeginner.help/standard-library/python-os-module-overview/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/python-os-module-overview/</guid><description>&lt;h1 id="python-os-module-overview"&gt;Python os Module Overview&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;os&lt;/code&gt; module helps Python work with your operating system. Beginners often use it for files, folders, paths, and environment information.&lt;/p&gt;
&lt;p&gt;It is part of Python’s standard library, so you do not need to install anything.&lt;/p&gt;
&lt;p&gt;This page is an overview of what &lt;code&gt;os&lt;/code&gt; does and when to use it. It is not a full guide to every function in the module.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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="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;getcwd&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&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This quick example:&lt;/p&gt;</description></item><item><title>Python pass Statement Explained</title><link>https://pythonbeginner.help/learn/python-pass-statement-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-pass-statement-explained/</guid><description>&lt;h1 id="python-pass-statement-explained"&gt;Python &lt;code&gt;pass&lt;/code&gt; Statement Explained&lt;/h1&gt;
&lt;p&gt;The Python &lt;code&gt;pass&lt;/code&gt; statement is used when Python expects a block of code, but you do not want to add any real code yet.&lt;/p&gt;
&lt;p&gt;Beginners often see &lt;code&gt;pass&lt;/code&gt; in early practice programs, unfinished functions, or simple examples. It helps you write the structure of your program first without causing a syntax error.&lt;/p&gt;
&lt;p&gt;The sections below show where &lt;code&gt;pass&lt;/code&gt; fits, how it differs from comments and loop controls, and when you should not reach for it.&lt;/p&gt;</description></item><item><title>Python Password Generator Example</title><link>https://pythonbeginner.help/examples/python-password-generator-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-password-generator-example/</guid><description>&lt;h1 id="python-password-generator-example"&gt;Python Password Generator Example&lt;/h1&gt;
&lt;p&gt;This example shows how to build a simple password generator in Python.&lt;/p&gt;
&lt;p&gt;You will learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;generate a random password&lt;/li&gt;
&lt;li&gt;use built-in Python modules&lt;/li&gt;
&lt;li&gt;combine letters, numbers, and symbols&lt;/li&gt;
&lt;li&gt;print one password to the screen&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want a quick working version first, use this script:&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;random&lt;/span&gt;
&lt;/span&gt;&lt;/span&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;string&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;length&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;characters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ascii_letters&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;digits&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;punctuation&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;&amp;#39;&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="n"&gt;random&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;characters&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;_&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;length&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&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 creates a random 12-character password using:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;uppercase and lowercase letters&lt;/li&gt;
&lt;li&gt;numbers&lt;/li&gt;
&lt;li&gt;symbols&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="what-this-example-does"&gt;What this example does &lt;a class="heading-anchor" href="#what-this-example-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This script:&lt;/p&gt;</description></item><item><title>Python Ping Script Example</title><link>https://pythonbeginner.help/examples/python-ping-script-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-ping-script-example/</guid><description>&lt;h1 id="python-ping-script-example"&gt;Python Ping Script Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to make a simple Python ping script by running your operating system&amp;rsquo;s &lt;code&gt;ping&lt;/code&gt; command.&lt;/p&gt;
&lt;p&gt;This is useful when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;check whether a host can be reached&lt;/li&gt;
&lt;li&gt;test basic network connectivity&lt;/li&gt;
&lt;li&gt;learn how Python can run terminal commands&lt;/li&gt;
&lt;li&gt;build a small troubleshooting script&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Python does not have a simple built-in &lt;code&gt;ping()&lt;/code&gt; function for this. A common beginner approach is to run the system command with &lt;code&gt;subprocess&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Python print() Function Explained</title><link>https://pythonbeginner.help/reference/python-print-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-print-function-explained/</guid><description>&lt;h1 id="python-print-function-explained"&gt;Python &lt;code&gt;print()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The Python &lt;code&gt;print()&lt;/code&gt; function displays output in the terminal or console. It is one of the first functions beginners learn because it lets you show text, numbers, variable values, and calculation results.&lt;/p&gt;
&lt;p&gt;This page explains the basic syntax of &lt;code&gt;print()&lt;/code&gt;, its most useful optional arguments, and common beginner mistakes.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;Mia&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;12&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="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 class="nb"&gt;print&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 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;/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="n"&gt;Mia&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="mi"&gt;12&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;Hello&lt;/span&gt; &lt;span class="n"&gt;Mia&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;print()&lt;/code&gt; to show text, numbers, and variable values on the screen.&lt;/p&gt;</description></item><item><title>Python random Module Overview</title><link>https://pythonbeginner.help/standard-library/python-random-module-overview/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/python-random-module-overview/</guid><description>&lt;h1 id="python-random-module-overview"&gt;Python random Module Overview&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;random&lt;/code&gt; module is a built-in Python module for working with pseudo-random values.&lt;/p&gt;
&lt;p&gt;Beginners often use it to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;generate random numbers&lt;/li&gt;
&lt;li&gt;choose a random item from a list&lt;/li&gt;
&lt;li&gt;shuffle a list&lt;/li&gt;
&lt;li&gt;pick several random items&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is useful for games, simple scripts, testing, and practice programs.&lt;/p&gt;
&lt;p&gt;It is &lt;strong&gt;not&lt;/strong&gt; the right tool for passwords, secure tokens, or anything security-related. For that, use the &lt;code&gt;secrets&lt;/code&gt; module instead.&lt;/p&gt;</description></item><item><title>Python Random Name Picker Example</title><link>https://pythonbeginner.help/examples/python-random-name-picker-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-random-name-picker-example/</guid><description>&lt;h1 id="python-random-name-picker-example"&gt;Python Random Name Picker Example&lt;/h1&gt;
&lt;p&gt;A simple Python project can help you practice lists, user input, and basic randomness.&lt;/p&gt;
&lt;p&gt;In this example, you will build a script that picks one random name from a list. This page focuses on how the script works and how to build it step by step, not on covering the full &lt;code&gt;random&lt;/code&gt; module.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;random&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;names&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;Alice&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Bob&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Carlos&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Dina&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;chosen_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&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;Selected:&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chosen_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;Use &lt;code&gt;random.choice()&lt;/code&gt; to return one item from a list. The list must not be empty.&lt;/p&gt;</description></item><item><title>Python Random Password List Generator Example</title><link>https://pythonbeginner.help/examples/python-random-password-list-generator-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-random-password-list-generator-example/</guid><description>&lt;h1 id="python-random-password-list-generator-example"&gt;Python Random Password List Generator Example&lt;/h1&gt;
&lt;p&gt;This example shows how to build a simple Python script that generates a list of random passwords.&lt;/p&gt;
&lt;p&gt;You will use:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the &lt;code&gt;random&lt;/code&gt; module&lt;/li&gt;
&lt;li&gt;strings of allowed characters&lt;/li&gt;
&lt;li&gt;loops&lt;/li&gt;
&lt;li&gt;a little user input for customization&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a good beginner project because it combines several basic Python ideas in one small program.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;random&lt;/span&gt;
&lt;/span&gt;&lt;/span&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;string&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;characters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ascii_letters&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;digits&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;punctuation&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;_&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;5&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;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;&amp;#39;&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="n"&gt;random&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;characters&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;_&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;12&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;password&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 quick example prints 5 random passwords, each 12 characters long.&lt;/p&gt;</description></item><item><title>Python range() Function Explained</title><link>https://pythonbeginner.help/reference/python-range-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-range-function-explained/</guid><description>&lt;h1 id="python-range-function-explained"&gt;Python &lt;code&gt;range()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The Python &lt;code&gt;range()&lt;/code&gt; function creates a sequence of numbers.&lt;/p&gt;
&lt;p&gt;Beginners usually use it in &lt;code&gt;for&lt;/code&gt; loops to repeat something a certain number of times or to work with number patterns. A very important detail is that &lt;code&gt;range()&lt;/code&gt; stops &lt;strong&gt;before&lt;/strong&gt; the end value.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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;5&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="c1"&gt;# Output:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&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 class="c1"&gt;# 1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# 2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# 3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# 4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;range(5)&lt;/code&gt; creates numbers starting at &lt;code&gt;0&lt;/code&gt; and stopping before &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Python range() vs list(range()) Explained</title><link>https://pythonbeginner.help/reference/python-range-vs-listrange-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-range-vs-listrange-explained/</guid><description>&lt;h1 id="python-range-vs-listrange-explained"&gt;Python &lt;code&gt;range()&lt;/code&gt; vs &lt;code&gt;list(range())&lt;/code&gt; Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;range()&lt;/code&gt; and &lt;code&gt;list(range())&lt;/code&gt; can represent the same numbers, but they are not the same thing.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;range()&lt;/code&gt; creates a &lt;strong&gt;range object&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;list(range())&lt;/code&gt; creates a &lt;strong&gt;real list&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This matters because beginners often expect &lt;code&gt;range(5)&lt;/code&gt; to behave exactly like &lt;code&gt;[0, 1, 2, 3, 4]&lt;/code&gt;. It does not. In most cases, you should use &lt;code&gt;range()&lt;/code&gt; for looping, and only use &lt;code&gt;list(range())&lt;/code&gt; when you actually need a list.&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="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&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;5&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="c1"&gt;# range(0, 5)&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;list&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="c1"&gt;# [0, 1, 2, 3, 4]&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;range()&lt;/code&gt; for looping. Use &lt;code&gt;list(range())&lt;/code&gt; when you need an actual list value.&lt;/p&gt;</description></item><item><title>Python Read and Write Text File Example</title><link>https://pythonbeginner.help/examples/python-read-and-write-text-file-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-read-and-write-text-file-example/</guid><description>&lt;h1 id="python-read-and-write-text-file-example"&gt;Python Read and Write Text File Example&lt;/h1&gt;
&lt;p&gt;This example shows a small Python script that writes text to a file and then reads it back.&lt;/p&gt;
&lt;p&gt;It is a practical beginner example. The goal is simple: create or overwrite a text file, add some text, read the file, and print the result.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;file_name&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;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_name&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="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="s2"&gt;&amp;#34;Hello, Python!&lt;/span&gt;&lt;span class="se"&gt;\n&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;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="s2"&gt;&amp;#34;This is a text file example.&lt;/span&gt;&lt;span class="se"&gt;\n&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;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="n"&gt;file_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;r&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;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&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 creates or overwrites a text file, writes two lines, reads the full file, and prints the result.&lt;/p&gt;</description></item><item><title>Python Remove Duplicates from Data Example</title><link>https://pythonbeginner.help/examples/python-remove-duplicates-from-data-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-remove-duplicates-from-data-example/</guid><description>&lt;h1 id="python-remove-duplicates-from-data-example"&gt;Python Remove Duplicates from Data Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows simple ways to remove duplicate values from Python data.&lt;/p&gt;
&lt;p&gt;The focus is on lists, because that is where this problem appears most often. You will see:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;how to remove repeated items quickly&lt;/li&gt;
&lt;li&gt;how to keep the original order when needed&lt;/li&gt;
&lt;li&gt;how to do the same job step by step with a loop&lt;/li&gt;
&lt;/ul&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="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;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;orange&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&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;unique_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fromkeys&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&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;unique_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="c1"&gt;# [&amp;#39;apple&amp;#39;, &amp;#39;banana&amp;#39;, &amp;#39;orange&amp;#39;]&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.fromkeys()&lt;/code&gt; when you want to remove duplicates and keep the original order.&lt;/p&gt;</description></item><item><title>Python Rename Files in a Folder Example</title><link>https://pythonbeginner.help/examples/python-rename-files-in-a-folder-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-rename-files-in-a-folder-example/</guid><description>&lt;h1 id="python-rename-files-in-a-folder-example"&gt;Python Rename Files in a Folder Example&lt;/h1&gt;
&lt;p&gt;If you want to rename many files in one folder, Python can do it with a short script.&lt;/p&gt;
&lt;p&gt;This beginner-friendly example shows how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;loop through files in a folder&lt;/li&gt;
&lt;li&gt;rename each file with a simple pattern&lt;/li&gt;
&lt;li&gt;keep the original file extension&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;pathlib&lt;/code&gt; for clearer file path handling&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page focuses on one folder only. It does &lt;strong&gt;not&lt;/strong&gt; rename files inside subfolders.&lt;/p&gt;</description></item><item><title>Python round() Function Explained</title><link>https://pythonbeginner.help/reference/python-round-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-round-function-explained/</guid><description>&lt;h1 id="python-round-function-explained"&gt;Python &lt;code&gt;round()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The built-in &lt;code&gt;round()&lt;/code&gt; function returns a rounded version of a number.&lt;/p&gt;
&lt;p&gt;You can use it in two common ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;round(number)&lt;/code&gt; rounds to the nearest whole number&lt;/li&gt;
&lt;li&gt;&lt;code&gt;round(number, digits)&lt;/code&gt; rounds to a chosen number of decimal places&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is useful when you want cleaner numeric output or when you need to limit decimal places in a result.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.14159&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="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.14159&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;/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="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="mf"&gt;3.14&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;round(number)&lt;/code&gt; to round to the nearest whole number, or &lt;code&gt;round(number, digits)&lt;/code&gt; to keep a set number of decimal places.&lt;/p&gt;</description></item><item><title>Python Search Algorithm Example (Linear Search)</title><link>https://pythonbeginner.help/examples/python-search-algorithm-example-linear-search/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-search-algorithm-example-linear-search/</guid><description>&lt;h1 id="python-search-algorithm-example-linear-search"&gt;Python Search Algorithm Example (Linear Search)&lt;/h1&gt;
&lt;p&gt;Linear search is one of the simplest ways to find a value in Python.&lt;/p&gt;
&lt;p&gt;It works by checking items one by one from left to right until it finds a match. This makes it a great beginner example because it uses basic ideas like loops, comparisons, and return values.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;linear_search&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 class="n"&gt;target&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;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;enumerate&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="k"&gt;if&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;target&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="n"&gt;index&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="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="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;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&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;9&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="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;linear_search&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;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 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;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>Python Set add() Method</title><link>https://pythonbeginner.help/reference/python-set-add-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-add-method/</guid><description>&lt;h1 id="python-set-add-method"&gt;Python Set &lt;code&gt;add()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;set.add()&lt;/code&gt; adds one item to a set.&lt;/p&gt;
&lt;p&gt;Use it when you want to put a single value into an existing set. If that value is not already present, Python adds it. If it is already in the set, nothing changes.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&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&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;
&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="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 class="mi"&gt;4&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;add()&lt;/code&gt; to put one value into a set. If the value is already in the set, nothing changes.&lt;/p&gt;</description></item><item><title>Python Set clear() Method</title><link>https://pythonbeginner.help/reference/python-set-clear-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-clear-method/</guid><description>&lt;h1 id="python-set-clear-method"&gt;Python Set &lt;code&gt;clear()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;set.clear()&lt;/code&gt; removes all items from a set.&lt;/p&gt;
&lt;p&gt;Use it when you want to empty a set &lt;strong&gt;without changing the variable itself&lt;/strong&gt;. This method changes the existing set in place, which is important when the same set is used in more than one place.&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;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="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clear&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&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="nb"&gt;set&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;code&gt;clear()&lt;/code&gt; removes all items from the set in place. It does not create a new set.&lt;/p&gt;
&lt;h2 id="what-setclear-does"&gt;What &lt;code&gt;set.clear()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-setclear-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;clear()&lt;/code&gt; method:&lt;/p&gt;</description></item><item><title>Python Set difference() Method</title><link>https://pythonbeginner.help/reference/python-set-difference-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-difference-method/</guid><description>&lt;h1 id="python-set-difference-method"&gt;Python Set &lt;code&gt;difference()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;set.difference()&lt;/code&gt; returns the values that are in one set but not in another.&lt;/p&gt;
&lt;p&gt;This is useful when you want to find items that exist in the first set and remove anything that also appears in one or more other sets.&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="n"&gt;a&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 class="mi"&gt;4&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;b&lt;/span&gt; &lt;span class="o"&gt;=&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 class="mi"&gt;4&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;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;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;difference&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;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;
&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="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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;difference()&lt;/code&gt; returns a new set with items from &lt;code&gt;a&lt;/code&gt; that are not in &lt;code&gt;b&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Python Set discard() Method</title><link>https://pythonbeginner.help/reference/python-set-discard-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-discard-method/</guid><description>&lt;h1 id="python-set-discard-method"&gt;Python Set &lt;code&gt;discard()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;set.discard()&lt;/code&gt; removes one item from a set.&lt;/p&gt;
&lt;p&gt;Use it when you want to remove a value safely, even if that value might not be in the set. Unlike &lt;a href="https://pythonbeginner.help/reference/python-set-remove-method/"&gt;&lt;code&gt;set.remove()&lt;/code&gt;&lt;/a&gt;, &lt;code&gt;discard()&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; raise an error for a missing item.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;blue&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&gt;&lt;/span&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="n"&gt;discard&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 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&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;colors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;discard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;yellow&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# no error if missing&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&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Possible 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;red&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;green&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;red&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;green&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;Use &lt;code&gt;discard()&lt;/code&gt; when you want to remove a value from a set safely, even if that value may not exist.&lt;/p&gt;</description></item><item><title>Python Set intersection() Method</title><link>https://pythonbeginner.help/reference/python-set-intersection-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-intersection-method/</guid><description>&lt;h1 id="python-set-intersection-method"&gt;Python Set &lt;code&gt;intersection()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;set.intersection()&lt;/code&gt; method returns a new set containing only the values that appear in both sets.&lt;/p&gt;
&lt;p&gt;Use it when you want to find common items between sets without changing the original set.&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;a&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="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&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 class="mi"&gt;4&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;intersection&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;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="c1"&gt;# Output: {2, 3}&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;intersection()&lt;/code&gt; when you want only the items that appear in both sets.&lt;/p&gt;
&lt;figure class="diagram" role="group" aria-label="`a.intersection(b)` shades only the overlap: values found in both sets."&gt;
&lt;svg width="400" height="250" viewBox="0 0 400 250" class="d-svg" xmlns="http://www.w3.org/2000/svg" role="img"&gt;
 &lt;defs&gt;
 &lt;clipPath id="vclipA"&gt;&lt;circle cx="150" cy="130" r="95"/&gt;&lt;/clipPath&gt;
 &lt;clipPath id="vclipB"&gt;&lt;circle cx="250" cy="130" r="95"/&gt;&lt;/clipPath&gt;
 &lt;/defs&gt;&lt;circle cx="150" cy="130" r="95" class="d-venn-base"/&gt;
 &lt;circle cx="250" cy="130" r="95" class="d-venn-base"/&gt;&lt;g clip-path="url(#vclipA)"&gt;&lt;circle cx="250" cy="130" r="95" class="d-venn-fill"/&gt;&lt;/g&gt;&lt;circle cx="150" cy="130" r="95" class="d-venn-outline"/&gt;
 &lt;circle cx="250" cy="130" r="95" class="d-venn-outline"/&gt;&lt;text x="95" y="70" class="d-venn-label" text-anchor="middle"&gt;a&lt;/text&gt;
 &lt;text x="305" y="70" class="d-venn-label" text-anchor="middle"&gt;b&lt;/text&gt;&lt;text x="102" y="130" class="d-venn-item" dominant-baseline="central" text-anchor="middle"&gt;1&lt;/text&gt;&lt;text x="200" y="119" class="d-venn-item" dominant-baseline="central" text-anchor="middle"&gt;2&lt;/text&gt;&lt;text x="200" y="141" class="d-venn-item" dominant-baseline="central" text-anchor="middle"&gt;3&lt;/text&gt;&lt;text x="298" y="130" class="d-venn-item" dominant-baseline="central" text-anchor="middle"&gt;4&lt;/text&gt;&lt;/svg&gt;&lt;figcaption&gt;&lt;code&gt;a.intersection(b)&lt;/code&gt; shades only the overlap: values found in both sets.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id="what-the-intersection-method-does"&gt;What the &lt;code&gt;intersection()&lt;/code&gt; method does &lt;a class="heading-anchor" href="#what-the-intersection-method-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;intersection()&lt;/code&gt; is a set method that compares one set with another set or iterable and keeps only the shared values.&lt;/p&gt;</description></item><item><title>Python Set pop() Method</title><link>https://pythonbeginner.help/reference/python-set-pop-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-pop-method/</guid><description>&lt;h1 id="python-set-pop-method"&gt;Python Set &lt;code&gt;pop()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;set.pop()&lt;/code&gt; removes and returns one item from a set.&lt;/p&gt;
&lt;p&gt;This method is useful when you want to take out any item, but you do &lt;strong&gt;not&lt;/strong&gt; care which one. That is important because sets are unordered, so &lt;code&gt;pop()&lt;/code&gt; does not remove an item by position.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;cherry&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;removed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pop&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;removed&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;items&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;
&lt;ul&gt;
&lt;li&gt;Removes one item from &lt;code&gt;items&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Stores that removed item in &lt;code&gt;removed&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Prints the removed item and the updated set&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; &lt;code&gt;set.pop()&lt;/code&gt; removes and returns one item from the set. The removed item is &lt;strong&gt;not&lt;/strong&gt; chosen by index.&lt;/p&gt;</description></item><item><title>Python Set remove() Method</title><link>https://pythonbeginner.help/reference/python-set-remove-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-remove-method/</guid><description>&lt;h1 id="python-set-remove-method"&gt;Python Set &lt;code&gt;remove()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;set.remove()&lt;/code&gt; deletes one specific value from a set.&lt;/p&gt;
&lt;p&gt;Use it when you want to remove an item &lt;strong&gt;and you expect that item to be present&lt;/strong&gt;. If the item is missing, Python raises a &lt;code&gt;KeyError&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;blue&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&gt;&lt;/span&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="n"&gt;remove&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 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&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Possible output:&lt;/strong&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="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;red&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;green&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;Use &lt;code&gt;remove()&lt;/code&gt; to delete a value from a set. If the value is not in the set, Python raises a &lt;code&gt;KeyError&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Python Set symmetric_difference() Method</title><link>https://pythonbeginner.help/reference/python-set-symmetric_difference-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-symmetric_difference-method/</guid><description>&lt;h1 id="python-set-symmetric_difference-method"&gt;Python Set &lt;code&gt;symmetric_difference()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;set.symmetric_difference()&lt;/code&gt; returns the values that appear in exactly one of two sets.&lt;/p&gt;
&lt;p&gt;This is useful when you want to compare two sets and keep only the non-matching values.&lt;/p&gt;
&lt;p&gt;Use it when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you want items in one set or the other&lt;/li&gt;
&lt;li&gt;you do &lt;strong&gt;not&lt;/strong&gt; want items that appear in both sets&lt;/li&gt;
&lt;li&gt;you need a new set without changing the originals&lt;/li&gt;
&lt;/ul&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="n"&gt;a&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="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&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 class="mi"&gt;4&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;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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;symmetric_difference&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;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 class="c1"&gt;# {1, 2, 4, 5}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use this when you want values that are in one set or the other, but not in both.&lt;/p&gt;</description></item><item><title>Python Set union() Method</title><link>https://pythonbeginner.help/reference/python-set-union-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-union-method/</guid><description>&lt;h1 id="python-set-union-method"&gt;Python Set &lt;code&gt;union()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;set.union()&lt;/code&gt; combines items from one set with items from one or more other iterables.&lt;/p&gt;
&lt;p&gt;It is useful when you want:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;all unique values from multiple collections&lt;/li&gt;
&lt;li&gt;a &lt;strong&gt;new set&lt;/strong&gt; as the result&lt;/li&gt;
&lt;li&gt;to keep the original set unchanged&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;set1&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="n"&gt;set2&lt;/span&gt; &lt;span class="o"&gt;=&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 class="mi"&gt;4&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;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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;set1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;union&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;set2&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;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# {1, 2, 3, 4, 5}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;union()&lt;/code&gt; returns a new set containing all unique items from both sets.&lt;/p&gt;</description></item><item><title>Python Set update() Method</title><link>https://pythonbeginner.help/reference/python-set-update-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-update-method/</guid><description>&lt;h1 id="python-set-update-method"&gt;Python Set &lt;code&gt;update()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;set.update()&lt;/code&gt; adds multiple items from another iterable into an existing set.&lt;/p&gt;
&lt;p&gt;Use it when you want to change a set in place with values from a list, tuple, set, string, or another iterable. It is different from &lt;a href="https://pythonbeginner.help/reference/python-set-add-method/"&gt;&lt;code&gt;set.add()&lt;/code&gt;&lt;/a&gt;, which adds only one item.&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="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&gt;&lt;/span&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="n"&gt;update&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 class="mi"&gt;4&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# {1, 2, 3, 4}&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;update()&lt;/code&gt; to add multiple items from a list, tuple, set, or other iterable into an existing set.&lt;/p&gt;</description></item><item><title>Python Set: Creating a Set</title><link>https://pythonbeginner.help/reference/python-set-creating-a-set/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-creating-a-set/</guid><description>&lt;h1 id="python-set-creating-a-set"&gt;Python Set: Creating a Set&lt;/h1&gt;
&lt;p&gt;This page shows how to create sets in Python, which syntax to use, and what happens with duplicates and empty sets.&lt;/p&gt;
&lt;p&gt;A set is useful when you want a collection of unique values. Unlike a list, a set does not keep duplicate items.&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="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="n"&gt;words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;apple&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;apple&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;empty_set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;set&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="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&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;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;empty_set&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;
&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="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="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;apple&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;set&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 curly braces with values for a non-empty set. Use &lt;code&gt;set()&lt;/code&gt; for an empty set.&lt;/p&gt;</description></item><item><title>Python set() Function Explained</title><link>https://pythonbeginner.help/reference/python-set-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-set-function-explained/</guid><description>&lt;h1 id="python-set-function-explained"&gt;Python set() Function Explained&lt;/h1&gt;
&lt;p&gt;The built-in &lt;code&gt;set()&lt;/code&gt; function creates a set in Python. A set is a collection that stores &lt;strong&gt;unique values only&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Beginners often use &lt;code&gt;set()&lt;/code&gt; to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;remove duplicates from a list&lt;/li&gt;
&lt;li&gt;check whether a value exists&lt;/li&gt;
&lt;li&gt;work with set operations like union and intersection&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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="n"&gt;unique_numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;set&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&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;unique_numbers&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;
&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="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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;set()&lt;/code&gt; to create a set from an iterable. A set keeps only unique values.&lt;/p&gt;</description></item><item><title>Python Sets Explained</title><link>https://pythonbeginner.help/learn/python-sets-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-sets-explained/</guid><description>&lt;h1 id="python-sets-explained"&gt;Python Sets Explained&lt;/h1&gt;
&lt;p&gt;A Python set is a built-in collection type that stores &lt;strong&gt;unique values only&lt;/strong&gt;. It is useful when you want to remove duplicates, check whether a value exists, or compare groups of items.&lt;/p&gt;
&lt;p&gt;Sets are different from lists and tuples because they are &lt;strong&gt;unordered&lt;/strong&gt;. That means items do not have a fixed position, and you cannot access them with an index like &lt;code&gt;my_set[0]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Below you will see how to create sets, add and remove items, and use them to compare groups of values.&lt;/p&gt;</description></item><item><title>Python shallow copy vs deep copy Explained</title><link>https://pythonbeginner.help/reference/python-shallow-copy-vs-deep-copy-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-shallow-copy-vs-deep-copy-explained/</guid><description>&lt;h1 id="python-shallow-copy-vs-deep-copy-explained"&gt;Python shallow copy vs deep copy Explained&lt;/h1&gt;
&lt;p&gt;When you copy data in Python, the result is not always fully independent from the original.&lt;/p&gt;
&lt;p&gt;This is especially important with nested data, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a list inside another list&lt;/li&gt;
&lt;li&gt;a dictionary containing lists&lt;/li&gt;
&lt;li&gt;a list of dictionaries&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The difference between &lt;strong&gt;shallow copy&lt;/strong&gt; and &lt;strong&gt;deep copy&lt;/strong&gt; is about what gets copied and what stays shared.&lt;/p&gt;
&lt;p&gt;If you get this wrong, changing one object can unexpectedly change another.&lt;/p&gt;</description></item><item><title>Python Simple Calculator Example</title><link>https://pythonbeginner.help/examples/python-simple-calculator-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-simple-calculator-example/</guid><description>&lt;h1 id="python-simple-calculator-example"&gt;Python Simple Calculator Example&lt;/h1&gt;
&lt;p&gt;A simple calculator is a great beginner Python project. It helps you practice several important basics in one small script:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;getting user input&lt;/li&gt;
&lt;li&gt;storing values in variables&lt;/li&gt;
&lt;li&gt;converting text to numbers&lt;/li&gt;
&lt;li&gt;using &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, and &lt;code&gt;else&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;doing basic math&lt;/li&gt;
&lt;li&gt;handling simple errors&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this example, you will build a calculator that asks for two numbers and an operator, then prints the result.&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;num1&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="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Enter first number: &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;operator&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 operator (+, -, *, /): &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;num2&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="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Enter second number: &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;if&lt;/span&gt; &lt;span class="n"&gt;operator&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="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;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;num2&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;elif&lt;/span&gt; &lt;span class="n"&gt;operator&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="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;num1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;num2&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;elif&lt;/span&gt; &lt;span class="n"&gt;operator&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="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;num1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;num2&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;elif&lt;/span&gt; &lt;span class="n"&gt;operator&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="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;num2&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="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;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;num1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;num2&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;Invalid operator&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 this as the main working example. The rest of the page explains each part step by step.&lt;/p&gt;</description></item><item><title>Python Simple Chatbot Example</title><link>https://pythonbeginner.help/examples/python-simple-chatbot-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-simple-chatbot-example/</guid><description>&lt;h1 id="python-simple-chatbot-example"&gt;Python Simple Chatbot Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to build a very simple chatbot in Python.&lt;/p&gt;
&lt;p&gt;It is a small terminal program that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;reads text from the user&lt;/li&gt;
&lt;li&gt;checks that text with &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, and &lt;code&gt;else&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;prints a fixed reply&lt;/li&gt;
&lt;li&gt;keeps running in a loop until the user types &lt;code&gt;bye&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This project is useful for practicing basic Python skills in one place.&lt;/p&gt;
&lt;p&gt;Important: this is &lt;strong&gt;not&lt;/strong&gt; an AI chatbot. It is a &lt;strong&gt;rule-based chatbot&lt;/strong&gt;, which means it only responds to messages you have programmed.&lt;/p&gt;</description></item><item><title>Python Simple Logging System Example</title><link>https://pythonbeginner.help/examples/python-simple-logging-system-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-simple-logging-system-example/</guid><description>&lt;h1 id="python-simple-logging-system-example"&gt;Python Simple Logging System Example&lt;/h1&gt;
&lt;p&gt;Build a small Python logging system that writes messages with timestamps and levels like &lt;code&gt;INFO&lt;/code&gt; and &lt;code&gt;ERROR&lt;/code&gt;. This example helps beginners understand how to record program activity in a simple, practical way.&lt;/p&gt;
&lt;p&gt;If you want a quick working version first, use 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="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&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&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;log_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;level&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 class="n"&gt;filename&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;app.log&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;timestamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;%Y-%m-&lt;/span&gt;&lt;span class="si"&gt;%d&lt;/span&gt;&lt;span class="s2"&gt; %H:%M:%S&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;line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;[&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;] &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&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="n"&gt;filename&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="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;line&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;log_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;INFO&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Program started&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;log_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;ERROR&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Something went wrong&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="s2"&gt;&amp;#34;Messages written to app.log&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 version appends log messages to a file so old messages are not erased.&lt;/p&gt;</description></item><item><title>Python Simple Web Scraper for Titles Example</title><link>https://pythonbeginner.help/examples/python-simple-web-scraper-for-titles-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-simple-web-scraper-for-titles-example/</guid><description>&lt;h1 id="python-simple-web-scraper-for-titles-example"&gt;Python Simple Web Scraper for Titles Example&lt;/h1&gt;
&lt;p&gt;Build a small Python script that downloads a web page and extracts page titles. This example is meant to be practical, short, and easy to run step by step.&lt;/p&gt;
&lt;p&gt;If you are new to packages, see &lt;a href="https://pythonbeginner.help/how-to/how-to-install-a-python-package-with-pip/"&gt;how to install a Python package with pip&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This is the fastest working example. It assumes &lt;code&gt;requests&lt;/code&gt; and &lt;code&gt;beautifulsoup4&lt;/code&gt; are installed.&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;requests&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;bs4&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BeautifulSoup&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;https://example.com&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&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="n"&gt;url&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;soup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;BeautifulSoup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;html.parser&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;soup&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;string&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;What it does:&lt;/p&gt;</description></item><item><title>Python sorted() Function Explained</title><link>https://pythonbeginner.help/reference/python-sorted-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-sorted-function-explained/</guid><description>&lt;h1 id="python-sorted-function-explained"&gt;Python &lt;code&gt;sorted()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;sorted()&lt;/code&gt; is a built-in Python function that returns a new list in sorted order.&lt;/p&gt;
&lt;p&gt;It is useful when you want to sort values without changing the original data. Unlike &lt;code&gt;list.sort()&lt;/code&gt;, &lt;code&gt;sorted()&lt;/code&gt; also works with many iterable types, not just lists.&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="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;3&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sorted&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&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="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 class="c1"&gt;# [1, 2, 3]&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="c1"&gt;# [3, 1, 2]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;sorted()&lt;/code&gt; returns a new sorted list and does not change the original object.&lt;/p&gt;</description></item><item><title>Python sorted() vs list.sort() Explained</title><link>https://pythonbeginner.help/reference/python-sorted-vs-list.sort-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-sorted-vs-list.sort-explained/</guid><description>&lt;h1 id="python-sorted-vs-listsort-explained"&gt;Python &lt;code&gt;sorted()&lt;/code&gt; vs &lt;code&gt;list.sort()&lt;/code&gt; Explained&lt;/h1&gt;
&lt;p&gt;Python gives you two common ways to sort values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;sorted()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;list.sort()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;They look similar, but they do &lt;strong&gt;not&lt;/strong&gt; behave the same way.&lt;/p&gt;
&lt;p&gt;The main difference is simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;sorted()&lt;/code&gt; when you want a &lt;strong&gt;new sorted result&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;list.sort()&lt;/code&gt; when you want to &lt;strong&gt;change the original list&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This matters a lot for beginners, especially when &lt;code&gt;list.sort()&lt;/code&gt; returns &lt;code&gt;None&lt;/code&gt; and causes confusion.&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="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;3&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;new_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sorted&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="c1"&gt;# returns a new sorted list&lt;/span&gt;
&lt;/span&gt;&lt;/span&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="n"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# sorts the original list in place&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;sorted()&lt;/code&gt; when you want a new result. Use &lt;code&gt;list.sort()&lt;/code&gt; when you want to change the existing list.&lt;/p&gt;</description></item><item><title>Python Sorting Algorithm Example (Bubble Sort)</title><link>https://pythonbeginner.help/examples/python-sorting-algorithm-example-bubble-sort/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-sorting-algorithm-example-bubble-sort/</guid><description>&lt;h1 id="python-sorting-algorithm-example-bubble-sort"&gt;Python Sorting Algorithm Example (Bubble Sort)&lt;/h1&gt;
&lt;p&gt;Bubble sort is a simple sorting algorithm that is often used for learning.&lt;/p&gt;
&lt;p&gt;In this example, you will see how bubble sort works in Python with a small step-by-step program. The goal is to understand the algorithm, not to use it as the main way to sort data in real projects.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Use this as a learning example. In normal Python code, &lt;a href="https://pythonbeginner.help/reference/python-sorted-function-explained/"&gt;&lt;code&gt;sorted()&lt;/code&gt;&lt;/a&gt; is usually the better choice.&lt;/p&gt;</description></item><item><title>Python Stopwatch Example</title><link>https://pythonbeginner.help/examples/python-stopwatch-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-stopwatch-example/</guid><description>&lt;h1 id="python-stopwatch-example"&gt;Python Stopwatch Example&lt;/h1&gt;
&lt;p&gt;Build a simple stopwatch in Python that measures elapsed time. This example uses the &lt;code&gt;time&lt;/code&gt; module and shows, step by step, how to record a start time, record an end time, and calculate the difference.&lt;/p&gt;
&lt;p&gt;If you are new to timing code in Python, this is a good first example because it uses only a few lines of code and one standard library module.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;time&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="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Press Enter to start the stopwatch...&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;start_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;time&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="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Press Enter to stop the stopwatch...&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;end_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;time&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;elapsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;end_time&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start_time&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;Elapsed time: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;elapsed&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;.2f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; seconds&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 is the simplest stopwatch version. It starts when you press Enter and stops when you press Enter again.&lt;/p&gt;</description></item><item><title>Python str() Function Explained</title><link>https://pythonbeginner.help/reference/python-str-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-str-function-explained/</guid><description>&lt;h1 id="python-str-function-explained"&gt;Python &lt;code&gt;str()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The Python &lt;code&gt;str()&lt;/code&gt; function converts a value into a string.&lt;/p&gt;
&lt;p&gt;A string is text in Python. Beginners often use &lt;code&gt;str()&lt;/code&gt; when they need to turn a number into text before combining it with other strings.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;25&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="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="nb"&gt;print&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="nb"&gt;type&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;&lt;strong&gt;Output:&lt;/strong&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="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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="err"&gt;&amp;#39;&lt;/span&gt;&lt;span class="nc"&gt;str&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;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;str()&lt;/code&gt; when you need a string version of a value, such as a number before joining or concatenating text.&lt;/p&gt;</description></item><item><title>Python String count() Method</title><link>https://pythonbeginner.help/reference/python-string-count-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-count-method/</guid><description>&lt;h1 id="python-string-count-method"&gt;Python String &lt;code&gt;count()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;count()&lt;/code&gt; method returns how many times a substring appears in a string.&lt;/p&gt;
&lt;p&gt;This reference page explains:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what &lt;code&gt;count()&lt;/code&gt; does&lt;/li&gt;
&lt;li&gt;its syntax&lt;/li&gt;
&lt;li&gt;what it returns&lt;/li&gt;
&lt;li&gt;how &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; work&lt;/li&gt;
&lt;li&gt;common beginner mistakes&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;banana&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;text&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&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&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;text&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;na&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;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="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="mi"&gt;2&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;string.count(value)&lt;/code&gt; to count how many times a substring appears in a string.&lt;/p&gt;
&lt;h2 id="what-the-count-method-does"&gt;What the &lt;code&gt;count()&lt;/code&gt; method does &lt;a class="heading-anchor" href="#what-the-count-method-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;count()&lt;/code&gt; tells you how many times some text appears inside a string.&lt;/p&gt;</description></item><item><title>Python String endswith() Method</title><link>https://pythonbeginner.help/reference/python-string-endswith-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-endswith-method/</guid><description>&lt;h1 id="python-string-endswith-method"&gt;Python String &lt;code&gt;endswith()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;endswith()&lt;/code&gt; method checks whether a string ends with specific text.&lt;/p&gt;
&lt;p&gt;It is useful when you want a simple &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt; answer. Beginners often use it for file extensions, URL endings, and checking user input.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;report.csv&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;filename&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;endswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;.csv&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;filename&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;endswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;.txt&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;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="kc"&gt;True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kc"&gt;False&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;endswith()&lt;/code&gt; when you want &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt; based on the ending of a string.&lt;/p&gt;
&lt;h2 id="what-endswith-does"&gt;What &lt;code&gt;endswith()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-endswith-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;endswith()&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>Python String find() Method</title><link>https://pythonbeginner.help/reference/python-string-find-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-find-method/</guid><description>&lt;h1 id="python-string-find-method"&gt;Python String &lt;code&gt;find()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;find()&lt;/code&gt; method searches for a substring inside a string.&lt;/p&gt;
&lt;p&gt;It returns the index of the first match. If the text is not found, it returns &lt;code&gt;-1&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Use &lt;code&gt;find()&lt;/code&gt; when you want the position of some text and it is normal for that text to be missing.&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;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;hello world&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;position&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;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;world&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;position&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 6&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;missing&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;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;python&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;missing&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# -1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;
&lt;p&gt;Use &lt;code&gt;find()&lt;/code&gt; when you want the position of a substring. It returns &lt;code&gt;-1&lt;/code&gt; if the substring is not found.&lt;/p&gt;</description></item><item><title>Python String format() Method</title><link>https://pythonbeginner.help/reference/python-string-format-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-format-method/</guid><description>&lt;h1 id="python-string-format-method"&gt;Python String &lt;code&gt;format()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;format()&lt;/code&gt; method inserts values into a string by replacing placeholders.&lt;/p&gt;
&lt;p&gt;It is a useful way to build readable messages without joining many strings together by hand.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;Maya&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;12&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="s2"&gt;&amp;#34;My name is &lt;/span&gt;&lt;span class="si"&gt;{}&lt;/span&gt;&lt;span class="s2"&gt; and I am &lt;/span&gt;&lt;span class="si"&gt;{}&lt;/span&gt;&lt;span class="s2"&gt; years old.&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;format&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 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 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;&lt;strong&gt;Output:&lt;/strong&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;My&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;Maya&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;I&lt;/span&gt; &lt;span class="n"&gt;am&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt; &lt;span class="n"&gt;old&lt;/span&gt;&lt;span class="o"&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;{}&lt;/code&gt; as placeholders, then pass values to &lt;code&gt;format()&lt;/code&gt; in the same order.&lt;/p&gt;
&lt;p&gt;If you are new to strings, see &lt;a href="https://pythonbeginner.help/learn/python-strings-explained-basics-and-examples/"&gt;Python strings explained: basics and examples&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python String index() Method</title><link>https://pythonbeginner.help/reference/python-string-index-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-index-method/</guid><description>&lt;h1 id="python-string-index-method"&gt;Python String &lt;code&gt;index()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;index()&lt;/code&gt; method returns the position of the first match inside a string.&lt;/p&gt;
&lt;p&gt;Use it when you want to find where a character or substring appears, and you expect that value to be present. If Python cannot find the value, it raises a &lt;code&gt;ValueError&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;hello world&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;position&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;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;world&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;position&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;# Output:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# 6&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;index()&lt;/code&gt; when you want the position of a substring and expect it to exist. If the value is missing, Python raises a &lt;code&gt;ValueError&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Python String join() Method</title><link>https://pythonbeginner.help/reference/python-string-join-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-join-method/</guid><description>&lt;h1 id="python-string-join-method"&gt;Python String &lt;code&gt;join()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;join()&lt;/code&gt; method combines multiple strings into one string.&lt;/p&gt;
&lt;p&gt;It is useful when you have a list or tuple of text values and want to join them with a separator such as a space, comma, dash, or nothing at all.&lt;/p&gt;
&lt;p&gt;A key rule to remember is this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You call &lt;code&gt;join()&lt;/code&gt; on the separator string&lt;/li&gt;
&lt;li&gt;Every item you join must already be a string&lt;/li&gt;
&lt;/ul&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="n"&gt;words&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;Python&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;is&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;fun&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="n"&gt;words&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>Python String lower() Method</title><link>https://pythonbeginner.help/reference/python-string-lower-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-lower-method/</guid><description>&lt;h1 id="python-string-lower-method"&gt;Python String &lt;code&gt;lower()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;lower()&lt;/code&gt; method returns a lowercase version of a string.&lt;/p&gt;
&lt;p&gt;It is useful when you want to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;convert text to lowercase&lt;/li&gt;
&lt;li&gt;compare text without case differences&lt;/li&gt;
&lt;li&gt;clean up user input&lt;/li&gt;
&lt;li&gt;make simple text matching easier&lt;/li&gt;
&lt;/ul&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;Hello WORLD&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;result&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;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="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 class="c1"&gt;# hello world&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; &lt;code&gt;lower()&lt;/code&gt; returns a new string. It does not change the original string in place.&lt;/p&gt;
&lt;h2 id="what-lower-does"&gt;What &lt;code&gt;lower()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-lower-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;lower()&lt;/code&gt; is a string method that changes uppercase letters to lowercase letters.&lt;/p&gt;</description></item><item><title>Python String replace() Method</title><link>https://pythonbeginner.help/reference/python-string-replace-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-replace-method/</guid><description>&lt;h1 id="python-string-replace-method"&gt;Python String &lt;code&gt;replace()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;replace()&lt;/code&gt; method lets you change text inside a string.&lt;/p&gt;
&lt;p&gt;This is a beginner-friendly reference page for &lt;code&gt;replace()&lt;/code&gt;. You will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what &lt;code&gt;replace()&lt;/code&gt; does&lt;/li&gt;
&lt;li&gt;how its syntax works&lt;/li&gt;
&lt;li&gt;how to replace all matches or only some matches&lt;/li&gt;
&lt;li&gt;common mistakes to avoid&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;I like cats&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;new_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;cats&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;dogs&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;new_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;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="n"&gt;I&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt; &lt;span class="n"&gt;dogs&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;replace(old, new)&lt;/code&gt; to return a new string with matching text changed. The original string is not modified.&lt;/p&gt;</description></item><item><title>Python String split() Method</title><link>https://pythonbeginner.help/reference/python-string-split-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-split-method/</guid><description>&lt;h1 id="python-string-split-method"&gt;Python String &lt;code&gt;split()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;split()&lt;/code&gt; method breaks a string into smaller parts and returns those parts as a list.&lt;/p&gt;
&lt;p&gt;Use it when you want to turn one string into multiple strings, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;splitting a sentence into words&lt;/li&gt;
&lt;li&gt;splitting comma-separated text&lt;/li&gt;
&lt;li&gt;breaking simple structured text into pieces&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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,cherry&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&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 class="c1"&gt;# [&amp;#39;apple&amp;#39;, &amp;#39;banana&amp;#39;, &amp;#39;cherry&amp;#39;]&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;split()&lt;/code&gt; when you want to turn one string into a list of smaller strings.&lt;/p&gt;</description></item><item><title>Python String startswith() Method</title><link>https://pythonbeginner.help/reference/python-string-startswith-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-startswith-method/</guid><description>&lt;h1 id="python-string-startswith-method"&gt;Python String &lt;code&gt;startswith()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;startswith()&lt;/code&gt; method checks whether a string begins with specific text.&lt;/p&gt;
&lt;p&gt;It is useful when you want a simple &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt; answer. Beginners often use it to test commands, filenames, labels, and other text patterns.&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;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Python Beginner Help&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&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;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Python&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# True&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;text&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Beginner&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# False&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;startswith()&lt;/code&gt; when you want to check whether a string begins with certain text.&lt;/p&gt;
&lt;h2 id="what-startswith-does"&gt;What &lt;code&gt;startswith()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-startswith-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;startswith()&lt;/code&gt; is a string method that checks the beginning of a string.&lt;/p&gt;</description></item><item><title>Python String strip() Method</title><link>https://pythonbeginner.help/reference/python-string-strip-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-strip-method/</guid><description>&lt;h1 id="python-string-strip-method"&gt;Python String &lt;code&gt;strip()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python &lt;code&gt;strip()&lt;/code&gt; method removes characters from the beginning and end of a string.&lt;/p&gt;
&lt;p&gt;Beginners usually use it to remove extra whitespace, such as spaces, tabs, and newline characters. This is especially useful when cleaning user input or processing text from a file.&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="n"&gt;text&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="n"&gt;clean_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;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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clean_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;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="n"&gt;hello&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 whitespace from both ends of a string. It does not change the original string.&lt;/p&gt;</description></item><item><title>Python String upper() Method</title><link>https://pythonbeginner.help/reference/python-string-upper-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-upper-method/</guid><description>&lt;h1 id="python-string-upper-method"&gt;Python String &lt;code&gt;upper()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;The Python string &lt;code&gt;upper()&lt;/code&gt; method returns a new string with lowercase letters changed to uppercase.&lt;/p&gt;
&lt;p&gt;This page explains what &lt;code&gt;upper()&lt;/code&gt; does, how to use it, what it returns, and a few common beginner mistakes. It stays focused on the method itself.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;Hello World&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;result&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;upper&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;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# HELLO WORLD&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;upper()&lt;/code&gt; returns a new string with letters changed to uppercase. It does &lt;strong&gt;not&lt;/strong&gt; change the original string in place.&lt;/p&gt;</description></item><item><title>Python String: Creating a String</title><link>https://pythonbeginner.help/reference/python-string-creating-a-string/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-string-creating-a-string/</guid><description>&lt;h1 id="python-string-creating-a-string"&gt;Python String: Creating a String&lt;/h1&gt;
&lt;p&gt;Learn the basic ways to create strings in Python. This page focuses only on making string values, not changing or processing them.&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;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="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Hello&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;empty&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="n"&gt;text&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="mi"&gt;123&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="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 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;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;empty&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;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;&lt;strong&gt;Note:&lt;/strong&gt; Use single quotes, double quotes, or &lt;code&gt;str()&lt;/code&gt; to create a string. Triple quotes are useful for multi-line text.&lt;/p&gt;
&lt;h2 id="what-this-page-covers"&gt;What this page covers &lt;a class="heading-anchor" href="#what-this-page-covers" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;What a string is in Python&lt;/li&gt;
&lt;li&gt;How to create a string with quotes&lt;/li&gt;
&lt;li&gt;How to create an empty string&lt;/li&gt;
&lt;li&gt;How to convert other values to strings with &lt;code&gt;str()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;When to use single, double, or triple quotes&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="what-a-string-is"&gt;What a string is &lt;a class="heading-anchor" href="#what-a-string-is" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A string is text data in Python.&lt;/p&gt;</description></item><item><title>Python Strings Explained (Basics and Examples)</title><link>https://pythonbeginner.help/learn/python-strings-explained-basics-and-examples/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-strings-explained-basics-and-examples/</guid><description>&lt;h1 id="python-strings-explained-basics-and-examples"&gt;Python Strings Explained (Basics and Examples)&lt;/h1&gt;
&lt;p&gt;Strings are one of the most common data types in Python.&lt;/p&gt;
&lt;p&gt;A string is used to store text. In this guide, you will learn what strings are, how to create them, and how to do basic string tasks like indexing, slicing, joining, and changing text.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use this short example to see what a string looks like, how to access characters, and how string methods work.&lt;/p&gt;</description></item><item><title>Python sum() Function Explained</title><link>https://pythonbeginner.help/reference/python-sum-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-sum-function-explained/</guid><description>&lt;h1 id="python-sum-function-explained"&gt;Python &lt;code&gt;sum()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The built-in &lt;code&gt;sum()&lt;/code&gt; function adds numbers from an iterable such as a list, tuple, or &lt;code&gt;range&lt;/code&gt; object.&lt;/p&gt;
&lt;p&gt;It is one of the simplest ways to get a total in Python. Beginners often use it to add all numbers in a list, but it also has an optional &lt;code&gt;start&lt;/code&gt; value and a few important limits.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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 class="mi"&gt;4&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;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sum&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&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;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 10&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;sum()&lt;/code&gt; to add numbers from an iterable like a list or tuple.&lt;/p&gt;</description></item><item><title>Python Syntax Basics Explained</title><link>https://pythonbeginner.help/learn/python-syntax-basics-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-syntax-basics-explained/</guid><description>&lt;h1 id="python-syntax-basics-explained"&gt;Python Syntax Basics Explained&lt;/h1&gt;
&lt;p&gt;Python syntax is the set of rules for writing Python code correctly. If your code follows these rules, Python can read and run it.&lt;/p&gt;
&lt;p&gt;This page explains the basic writing rules you need before learning variables, &lt;code&gt;if&lt;/code&gt; statements, loops, and functions. The goal is simple: help you read and write small pieces of valid Python code.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use this small example to see the main syntax rules in one place:&lt;/p&gt;</description></item><item><title>Python sys Module Overview</title><link>https://pythonbeginner.help/standard-library/python-sys-module-overview/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/python-sys-module-overview/</guid><description>&lt;h1 id="python-sys-module-overview"&gt;Python sys Module Overview&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;sys&lt;/code&gt; module is a built-in Python standard library module. It gives you access to information about the Python interpreter and some parts of the program runtime.&lt;/p&gt;
&lt;p&gt;Beginners often use &lt;code&gt;sys&lt;/code&gt; for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;reading command-line arguments&lt;/li&gt;
&lt;li&gt;stopping a program with &lt;code&gt;sys.exit()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;checking the Python version&lt;/li&gt;
&lt;li&gt;checking the platform&lt;/li&gt;
&lt;li&gt;understanding where Python looks for modules&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page is an overview of the most useful parts of &lt;code&gt;sys&lt;/code&gt;. It is not a full reference for every attribute in the module.&lt;/p&gt;</description></item><item><title>Python Text Analysis Script Example</title><link>https://pythonbeginner.help/examples/python-text-analysis-script-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-text-analysis-script-example/</guid><description>&lt;h1 id="python-text-analysis-script-example"&gt;Python Text Analysis Script Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to analyze text in Python.&lt;/p&gt;
&lt;p&gt;You will build a small script that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Counts characters&lt;/li&gt;
&lt;li&gt;Counts words&lt;/li&gt;
&lt;li&gt;Counts lines&lt;/li&gt;
&lt;li&gt;Counts how often each word appears&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is a good practice project because it uses basic Python tools in a real script: strings, loops, dictionaries, and printing results clearly.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use this small script if you want a fast example of basic text analysis without reading from a file.&lt;/p&gt;</description></item><item><title>Python time Module Overview</title><link>https://pythonbeginner.help/standard-library/python-time-module-overview/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/python-time-module-overview/</guid><description>&lt;h1 id="python-time-module-overview"&gt;Python time Module Overview&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;time&lt;/code&gt; module is a built-in Python module for simple time-related tasks.&lt;/p&gt;
&lt;p&gt;Beginners usually use it for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;getting the current timestamp&lt;/li&gt;
&lt;li&gt;pausing a program&lt;/li&gt;
&lt;li&gt;measuring how long code takes to run&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is a good starting point when you need something simple. If you need readable dates, calendar values, or date math, the &lt;a href="https://pythonbeginner.help/standard-library/python-datetime-module-overview/"&gt;&lt;code&gt;datetime&lt;/code&gt; module overview&lt;/a&gt; is usually a better fit.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;time&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;time&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;Waiting...&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;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Done&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;What this does:&lt;/p&gt;</description></item><item><title>Python Timer Script Example</title><link>https://pythonbeginner.help/examples/python-timer-script-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-timer-script-example/</guid><description>&lt;h1 id="python-timer-script-example"&gt;Python Timer Script Example&lt;/h1&gt;
&lt;p&gt;Build a simple Python timer script that waits for a number of seconds, shows progress, and prints a message when the timer finishes.&lt;/p&gt;
&lt;p&gt;This page focuses on a small runnable example, not a full guide to the &lt;code&gt;time&lt;/code&gt; module.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;time&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;seconds&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="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;Starting &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-second timer...&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="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seconds&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;Time is up!&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 is the simplest timer example. It pauses the program for 5 seconds, then prints a message.&lt;/p&gt;</description></item><item><title>Python To-Do List Script Example</title><link>https://pythonbeginner.help/examples/python-to-do-list-script-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-to-do-list-script-example/</guid><description>&lt;h1 id="python-to-do-list-script-example"&gt;Python To-Do List Script Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly project shows how to build a simple command-line to-do list script in Python.&lt;/p&gt;
&lt;p&gt;It is a good example because it combines several core Python skills in one small program:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;lists&lt;/li&gt;
&lt;li&gt;loops&lt;/li&gt;
&lt;li&gt;&lt;code&gt;input()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;if&lt;/code&gt; statements&lt;/li&gt;
&lt;li&gt;functions like &lt;code&gt;append()&lt;/code&gt; and &lt;code&gt;pop()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are still learning these basics, this example helps you see how they work together in a real script.&lt;/p&gt;
&lt;h2 id="what-this-script-does"&gt;What this script does &lt;a class="heading-anchor" href="#what-this-script-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This program:&lt;/p&gt;</description></item><item><title>Python Tuple count() Method</title><link>https://pythonbeginner.help/reference/python-tuple-count-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-tuple-count-method/</guid><description>&lt;h1 id="python-tuple-count-method"&gt;Python Tuple &lt;code&gt;count()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;tuple.count()&lt;/code&gt; tells you how many times a value appears in a tuple.&lt;/p&gt;
&lt;p&gt;Use it when you want to count matching values in a tuple without changing the tuple itself. This is helpful when checking for duplicates, repeated labels, or whether a value appears more than once.&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;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;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 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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&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="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 class="c1"&gt;# 3&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;tuple.count(value)&lt;/code&gt; to count how many times a value appears in a tuple.&lt;/p&gt;
&lt;h2 id="what-tuplecount-does"&gt;What &lt;code&gt;tuple.count()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-tuplecount-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;tuple.count(value)&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>Python Tuple index() Method</title><link>https://pythonbeginner.help/reference/python-tuple-index-method/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-tuple-index-method/</guid><description>&lt;h1 id="python-tuple-index-method"&gt;Python Tuple &lt;code&gt;index()&lt;/code&gt; Method&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;tuple.index()&lt;/code&gt; finds the position of a value inside a tuple.&lt;/p&gt;
&lt;p&gt;It is useful when you know the value you want to search for and need its index. This method returns the first matching position and raises an error if the value is not found.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;blue&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 class="n"&gt;position&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;colors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;index&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 class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;tuple.index(value)&lt;/code&gt; returns the position of the first matching item.&lt;/p&gt;
&lt;figure class="diagram" role="group" aria-label="`colors.index(&amp;#34;blue&amp;#34;)` returns 1 — the first `blue`, even though it appears twice."&gt;
&lt;svg width="256" height="130" viewBox="0 0 256 130" class="d-svg" xmlns="http://www.w3.org/2000/svg" role="img"&gt;&lt;rect x="16" y="26" width="56" height="48" rx="6"
 class="d-cell"/&gt;
 &lt;text x="44" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;red&lt;/text&gt;
 &lt;text x="44" y="17" class="d-idx" text-anchor="middle"&gt;0&lt;/text&gt;&lt;text x="44" y="91" class="d-idx-neg" text-anchor="middle"&gt;-4&lt;/text&gt;&lt;rect x="72" y="26" width="56" height="48" rx="6"
 class="d-cell-hl"/&gt;
 &lt;text x="100" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;blue&lt;/text&gt;
 &lt;text x="100" y="17" class="d-idx d-idx-hl" text-anchor="middle"&gt;1&lt;/text&gt;&lt;text x="100" y="91" class="d-idx-neg" text-anchor="middle"&gt;-3&lt;/text&gt;&lt;rect x="128" y="26" width="56" height="48" rx="6"
 class="d-cell"/&gt;
 &lt;text x="156" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;green&lt;/text&gt;
 &lt;text x="156" y="17" class="d-idx" text-anchor="middle"&gt;2&lt;/text&gt;&lt;text x="156" y="91" class="d-idx-neg" text-anchor="middle"&gt;-2&lt;/text&gt;&lt;rect x="184" y="26" width="56" height="48" rx="6"
 class="d-cell"/&gt;
 &lt;text x="212" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;blue&lt;/text&gt;
 &lt;text x="212" y="17" class="d-idx" text-anchor="middle"&gt;3&lt;/text&gt;&lt;text x="212" y="91" class="d-idx-neg" text-anchor="middle"&gt;-1&lt;/text&gt;&lt;path d="M72 104 v6 h56 v-6" class="d-bracket"/&gt;
 &lt;text x="100" y="126" class="d-bracket-label" text-anchor="middle"&gt;[1:2]&lt;/text&gt;&lt;/svg&gt;&lt;figcaption&gt;&lt;code&gt;colors.index(&amp;quot;blue&amp;quot;)&lt;/code&gt; returns 1 — the first &lt;code&gt;blue&lt;/code&gt;, even though it appears twice.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id="what-tupleindex-does"&gt;What &lt;code&gt;tuple.index()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-tupleindex-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;index()&lt;/code&gt; method:&lt;/p&gt;</description></item><item><title>Python Tuple Indexing Explained</title><link>https://pythonbeginner.help/reference/python-tuple-indexing-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-tuple-indexing-explained/</guid><description>&lt;h1 id="python-tuple-indexing-explained"&gt;Python Tuple Indexing Explained&lt;/h1&gt;
&lt;p&gt;Tuple indexing is how you access one item in a tuple by its position.&lt;/p&gt;
&lt;p&gt;Use this when you want to read a specific value from a tuple. On this page, the focus is on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;positive indexes&lt;/li&gt;
&lt;li&gt;negative indexes&lt;/li&gt;
&lt;li&gt;common indexing mistakes&lt;/li&gt;
&lt;li&gt;what happens when an index does not exist&lt;/li&gt;
&lt;/ul&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;p&gt;Use square brackets with a number after the tuple name.&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;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="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;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# red&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;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# green&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="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# blue&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;Index &lt;code&gt;0&lt;/code&gt; is the first item.&lt;/li&gt;
&lt;li&gt;Negative indexes count from the end.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure class="diagram" role="group" aria-label="`colors[0]` is `red`; `colors[-1]` is the last item, `blue`."&gt;
&lt;svg width="200" height="100" viewBox="0 0 200 100" class="d-svg" xmlns="http://www.w3.org/2000/svg" role="img"&gt;&lt;rect x="16" y="26" width="56" height="48" rx="6"
 class="d-cell"/&gt;
 &lt;text x="44" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;red&lt;/text&gt;
 &lt;text x="44" y="17" class="d-idx" text-anchor="middle"&gt;0&lt;/text&gt;&lt;text x="44" y="91" class="d-idx-neg" text-anchor="middle"&gt;-3&lt;/text&gt;&lt;rect x="72" y="26" width="56" height="48" rx="6"
 class="d-cell"/&gt;
 &lt;text x="100" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;green&lt;/text&gt;
 &lt;text x="100" y="17" class="d-idx" text-anchor="middle"&gt;1&lt;/text&gt;&lt;text x="100" y="91" class="d-idx-neg" text-anchor="middle"&gt;-2&lt;/text&gt;&lt;rect x="128" y="26" width="56" height="48" rx="6"
 class="d-cell"/&gt;
 &lt;text x="156" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;blue&lt;/text&gt;
 &lt;text x="156" y="17" class="d-idx" text-anchor="middle"&gt;2&lt;/text&gt;&lt;text x="156" y="91" class="d-idx-neg" text-anchor="middle"&gt;-1&lt;/text&gt;&lt;/svg&gt;&lt;figcaption&gt;&lt;code&gt;colors[0]&lt;/code&gt; is &lt;code&gt;red&lt;/code&gt;; &lt;code&gt;colors[-1]&lt;/code&gt; is the last item, &lt;code&gt;blue&lt;/code&gt;.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;If you need help creating tuples first, see &lt;a href="https://pythonbeginner.help/reference/python-tuple-creating-a-tuple/"&gt;how to create a tuple in Python&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python Tuple Length (len)</title><link>https://pythonbeginner.help/reference/python-tuple-length-len/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-tuple-length-len/</guid><description>&lt;h1 id="python-tuple-length-len"&gt;Python Tuple Length (&lt;code&gt;len&lt;/code&gt;)&lt;/h1&gt;
&lt;p&gt;Use &lt;code&gt;len()&lt;/code&gt; to get the number of items in a tuple.&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;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 class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&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="mi"&gt;3&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;len(tuple_name)&lt;/code&gt; to count how many items are in a tuple.&lt;/p&gt;
&lt;h2 id="what-this-page-covers"&gt;What this page covers &lt;a class="heading-anchor" href="#what-this-page-covers" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;How &lt;code&gt;len()&lt;/code&gt; works with tuples&lt;/li&gt;
&lt;li&gt;What value &lt;code&gt;len()&lt;/code&gt; returns&lt;/li&gt;
&lt;li&gt;Simple examples with empty and non-empty tuples&lt;/li&gt;
&lt;li&gt;Common beginner mistakes&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="basic-syntax"&gt;Basic syntax &lt;a class="heading-anchor" href="#basic-syntax" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use this pattern:&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="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_tuple&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;Important points:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pass the tuple inside the parentheses&lt;/li&gt;
&lt;li&gt;The result is an integer&lt;/li&gt;
&lt;li&gt;&lt;code&gt;len()&lt;/code&gt; does not change the tuple&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example:&lt;/p&gt;</description></item><item><title>Python Tuple Slicing Explained</title><link>https://pythonbeginner.help/reference/python-tuple-slicing-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-tuple-slicing-explained/</guid><description>&lt;h1 id="python-tuple-slicing-explained"&gt;Python Tuple Slicing Explained&lt;/h1&gt;
&lt;p&gt;Tuple slicing lets you get part of a tuple by using square brackets and colons. It is a simple way to take a range of values, skip values with a step, or reverse a tuple.&lt;/p&gt;
&lt;p&gt;Use this format:&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="nb"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;step&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;The &lt;code&gt;stop&lt;/code&gt; position is &lt;strong&gt;not included&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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 class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&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="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;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# (20, 30, 40)&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;3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# (10, 20, 30)&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;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# (10, 30, 50)&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="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# (50, 40, 30, 20, 10)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure class="diagram" role="group" aria-label="`numbers[1:4]` keeps indices 1, 2, 3 — stop index 4 is not included."&gt;
&lt;svg width="312" height="130" viewBox="0 0 312 130" class="d-svg" xmlns="http://www.w3.org/2000/svg" role="img"&gt;&lt;rect x="16" y="26" width="56" height="48" rx="6"
 class="d-cell"/&gt;
 &lt;text x="44" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;10&lt;/text&gt;
 &lt;text x="44" y="17" class="d-idx" text-anchor="middle"&gt;0&lt;/text&gt;&lt;text x="44" y="91" class="d-idx-neg" text-anchor="middle"&gt;-5&lt;/text&gt;&lt;rect x="72" y="26" width="56" height="48" rx="6"
 class="d-cell-hl"/&gt;
 &lt;text x="100" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;20&lt;/text&gt;
 &lt;text x="100" y="17" class="d-idx d-idx-hl" text-anchor="middle"&gt;1&lt;/text&gt;&lt;text x="100" y="91" class="d-idx-neg" text-anchor="middle"&gt;-4&lt;/text&gt;&lt;rect x="128" y="26" width="56" height="48" rx="6"
 class="d-cell-hl"/&gt;
 &lt;text x="156" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;30&lt;/text&gt;
 &lt;text x="156" y="17" class="d-idx d-idx-hl" text-anchor="middle"&gt;2&lt;/text&gt;&lt;text x="156" y="91" class="d-idx-neg" text-anchor="middle"&gt;-3&lt;/text&gt;&lt;rect x="184" y="26" width="56" height="48" rx="6"
 class="d-cell-hl"/&gt;
 &lt;text x="212" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;40&lt;/text&gt;
 &lt;text x="212" y="17" class="d-idx d-idx-hl" text-anchor="middle"&gt;3&lt;/text&gt;&lt;text x="212" y="91" class="d-idx-neg" text-anchor="middle"&gt;-2&lt;/text&gt;&lt;rect x="240" y="26" width="56" height="48" rx="6"
 class="d-cell"/&gt;
 &lt;text x="268" y="50" class="d-val" dominant-baseline="central" text-anchor="middle"&gt;50&lt;/text&gt;
 &lt;text x="268" y="17" class="d-idx" text-anchor="middle"&gt;4&lt;/text&gt;&lt;text x="268" y="91" class="d-idx-neg" text-anchor="middle"&gt;-1&lt;/text&gt;&lt;path d="M72 104 v6 h168 v-6" class="d-bracket"/&gt;
 &lt;text x="156" y="126" class="d-bracket-label" text-anchor="middle"&gt;[1:4]&lt;/text&gt;&lt;/svg&gt;&lt;figcaption&gt;&lt;code&gt;numbers[1:4]&lt;/code&gt; keeps indices 1, 2, 3 — stop index 4 is not included.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id="what-tuple-slicing-means"&gt;What tuple slicing means &lt;a class="heading-anchor" href="#what-tuple-slicing-means" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Slicing gets part of a tuple.&lt;/p&gt;</description></item><item><title>Python Tuple: Creating a Tuple</title><link>https://pythonbeginner.help/reference/python-tuple-creating-a-tuple/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-tuple-creating-a-tuple/</guid><description>&lt;h1 id="python-tuple-creating-a-tuple"&gt;Python Tuple: Creating a Tuple&lt;/h1&gt;
&lt;p&gt;A tuple is a simple way to store multiple values in one object. This page shows how to create tuples in Python, including empty tuples, one-item tuples, and tuples made from other iterable values.&lt;/p&gt;
&lt;p&gt;The focus here is only on tuple creation syntax. If you want a general introduction, see &lt;a href="https://pythonbeginner.help/glossary/what-is-a-tuple-in-python/"&gt;what is a tuple in Python&lt;/a&gt; or &lt;a href="https://pythonbeginner.help/learn/python-tuples-explained/"&gt;Python tuples explained&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="n"&gt;empty&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 class="n"&gt;one_item&lt;/span&gt; &lt;span class="o"&gt;=&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;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;from_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tuple&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="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&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;empty&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;one_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 class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;from_list&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>Python tuple() Function Explained</title><link>https://pythonbeginner.help/reference/python-tuple-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-tuple-function-explained/</guid><description>&lt;h1 id="python-tuple-function-explained"&gt;Python tuple() Function Explained&lt;/h1&gt;
&lt;p&gt;The built-in &lt;code&gt;tuple()&lt;/code&gt; function creates a tuple in Python.&lt;/p&gt;
&lt;p&gt;You can use it in two main ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;tuple()&lt;/code&gt; creates an empty tuple&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tuple(iterable)&lt;/code&gt; converts an iterable into a tuple&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is useful when you want a fixed, immutable sequence of values. Beginners often use &lt;code&gt;tuple()&lt;/code&gt; to convert a list, string, range, or other iterable into a tuple.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tuple&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&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="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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&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>Python Tuples Explained</title><link>https://pythonbeginner.help/learn/python-tuples-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-tuples-explained/</guid><description>&lt;h1 id="python-tuples-explained"&gt;Python Tuples Explained&lt;/h1&gt;
&lt;p&gt;A tuple is one of Python’s built-in collection types. It lets you store multiple values in a single object.&lt;/p&gt;
&lt;p&gt;Tuples are useful when values belong together and should not change after they are created. In this guide, you’ll learn what tuples are, how to create them, how to access their items, and when to use them instead of lists.&lt;/p&gt;
&lt;h2 id="what-a-tuple-is"&gt;What a tuple is &lt;a class="heading-anchor" href="#what-a-tuple-is" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A tuple is an &lt;strong&gt;ordered collection of values&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Python type() Function Explained</title><link>https://pythonbeginner.help/reference/python-type-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-type-function-explained/</guid><description>&lt;h1 id="python-type-function-explained"&gt;Python &lt;code&gt;type()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;The Python &lt;code&gt;type()&lt;/code&gt; function tells you what kind of value an object is.&lt;/p&gt;
&lt;p&gt;Beginners usually use &lt;code&gt;type()&lt;/code&gt; to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;check whether a value is a string, number, list, or dictionary&lt;/li&gt;
&lt;li&gt;understand what a variable currently contains&lt;/li&gt;
&lt;li&gt;debug confusing code&lt;/li&gt;
&lt;li&gt;inspect values returned by functions such as &lt;a href="https://pythonbeginner.help/reference/python-input-function-explained/"&gt;&lt;code&gt;input()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In most beginner code, you will use the one-argument form:&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="nb"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;object&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 also has a three-argument form of &lt;code&gt;type()&lt;/code&gt;, but that is an advanced feature for creating classes dynamically.&lt;/p&gt;</description></item><item><title>Python URL Checker Script Example</title><link>https://pythonbeginner.help/examples/python-url-checker-script-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-url-checker-script-example/</guid><description>&lt;h1 id="python-url-checker-script-example"&gt;Python URL Checker Script Example&lt;/h1&gt;
&lt;p&gt;This example shows a simple Python script that checks whether URLs respond successfully.&lt;/p&gt;
&lt;p&gt;You will learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;check one or more URLs from Python&lt;/li&gt;
&lt;li&gt;send an HTTP request to each URL&lt;/li&gt;
&lt;li&gt;read the response status code&lt;/li&gt;
&lt;li&gt;handle errors without stopping the whole script&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a practical beginner-friendly example. The goal is to understand the script, run it, and then make small improvements.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;requests&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;urls&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 class="s2"&gt;&amp;#34;https://www.python.org&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="s2"&gt;&amp;#34;https://example.com&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="s2"&gt;&amp;#34;https://this-url-does-not-exist-12345.com&amp;#34;&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&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;url&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;urls&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;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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&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="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&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;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;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&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="n"&gt;requests&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RequestException&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&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;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;ERROR:&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&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 is the fastest working example. It checks each URL and prints either the status code or an error.&lt;/p&gt;</description></item><item><title>Python Variables Explained for Beginners</title><link>https://pythonbeginner.help/learn/python-variables-explained-for-beginners/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-variables-explained-for-beginners/</guid><description>&lt;h1 id="python-variables-explained-for-beginners"&gt;Python Variables Explained for Beginners&lt;/h1&gt;
&lt;p&gt;Variables are one of the first things you learn in Python.&lt;/p&gt;
&lt;p&gt;A variable is a name that points to a value. You use variables to store data, reuse it later, and make your programs easier to read.&lt;/p&gt;
&lt;p&gt;In Python, you create a variable by assigning a value with the &lt;code&gt;=&lt;/code&gt; sign. You do not need a special keyword like &lt;code&gt;var&lt;/code&gt; or &lt;code&gt;let&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s walk through how to create variables, name them well, and avoid the mistakes beginners run into most.&lt;/p&gt;</description></item><item><title>Python Weather API Example</title><link>https://pythonbeginner.help/examples/python-weather-api-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-weather-api-example/</guid><description>&lt;h1 id="python-weather-api-example"&gt;Python Weather API Example&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to request weather data from an API, read the JSON response, and print a few useful values.&lt;/p&gt;
&lt;p&gt;The goal here is to build a simple real-world Python example. You do not need to fully understand HTTP yet. You only need to see the basic pattern:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Send a request&lt;/li&gt;
&lt;li&gt;Get data back&lt;/li&gt;
&lt;li&gt;Read the JSON&lt;/li&gt;
&lt;li&gt;Print the values you want&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;requests&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;https://api.open-meteo.com/v1/forecast&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;params&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 class="s2"&gt;&amp;#34;latitude&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;40.7128&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="s2"&gt;&amp;#34;longitude&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;74.0060&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="s2"&gt;&amp;#34;current_weather&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&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&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&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="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;params&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&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="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;current_weather&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;temperature&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;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;current_weather&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;windspeed&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 uses the free Open-Meteo API and the &lt;code&gt;requests&lt;/code&gt; package.&lt;/p&gt;</description></item><item><title>Python Web Scraping Example (BeautifulSoup)</title><link>https://pythonbeginner.help/examples/python-web-scraping-example-beautifulsoup/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-web-scraping-example-beautifulsoup/</guid><description>&lt;h1 id="python-web-scraping-example-beautifulsoup"&gt;Python Web Scraping Example (BeautifulSoup)&lt;/h1&gt;
&lt;p&gt;This beginner-friendly example shows how to download a web page, parse its HTML with BeautifulSoup, and extract simple data like the page title and links.&lt;/p&gt;
&lt;p&gt;The goal is to help you build a small working scraper. This page focuses on a practical example, not every detail of web scraping.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;requests&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;bs4&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BeautifulSoup&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;https://example.com&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&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="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&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;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;raise_for_status&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;soup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;BeautifulSoup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;html.parser&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Page title:&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;soup&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;string&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;link&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;soup&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find_all&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&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;link&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;href&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;&lt;strong&gt;Note:&lt;/strong&gt; This is a minimal working example. You need to install &lt;code&gt;requests&lt;/code&gt; and &lt;code&gt;beautifulsoup4&lt;/code&gt; first.&lt;/p&gt;</description></item><item><title>Python while Loops Explained</title><link>https://pythonbeginner.help/learn/python-while-loops-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/python-while-loops-explained/</guid><description>&lt;h1 id="python-while-loops-explained"&gt;Python while Loops Explained&lt;/h1&gt;
&lt;p&gt;A &lt;code&gt;while&lt;/code&gt; loop lets you repeat code as long as a condition stays &lt;code&gt;True&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is useful when you do not know in advance how many times the loop should run. Python checks the condition before each run of the loop. When the condition becomes &lt;code&gt;False&lt;/code&gt;, the loop stops.&lt;/p&gt;
&lt;p&gt;Below you&amp;rsquo;ll see how to count with a &lt;code&gt;while&lt;/code&gt; loop, how each pass is checked, and how to keep your loop from running forever.&lt;/p&gt;</description></item><item><title>Python Word Count Script Example</title><link>https://pythonbeginner.help/examples/python-word-count-script-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-word-count-script-example/</guid><description>&lt;h1 id="python-word-count-script-example"&gt;Python Word Count Script Example&lt;/h1&gt;
&lt;p&gt;This example shows a simple way to count words in Python.&lt;/p&gt;
&lt;p&gt;You will build a small script that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;takes a piece of text&lt;/li&gt;
&lt;li&gt;splits it into words with &lt;code&gt;split()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;counts those words with &lt;code&gt;len()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a beginner-friendly example focused on one practical task. It does &lt;strong&gt;not&lt;/strong&gt; try to do advanced text analysis.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;Python makes word counting simple&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;words&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&gt;&lt;/span&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="nb"&gt;len&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;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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Word count:&amp;#34;&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;/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>Python Working with Dates Example</title><link>https://pythonbeginner.help/examples/python-working-with-dates-example/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/examples/python-working-with-dates-example/</guid><description>&lt;h1 id="python-working-with-dates-example"&gt;Python Working with Dates Example&lt;/h1&gt;
&lt;p&gt;Python can work with dates and times using the &lt;code&gt;datetime&lt;/code&gt; module. In this example, you will learn how to do common date tasks with small, clear examples.&lt;/p&gt;
&lt;p&gt;You will see how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Get the current date&lt;/li&gt;
&lt;li&gt;Get the current date and time&lt;/li&gt;
&lt;li&gt;Format dates as readable text&lt;/li&gt;
&lt;li&gt;Convert a string into a date&lt;/li&gt;
&lt;li&gt;Compare dates&lt;/li&gt;
&lt;li&gt;Find the number of days between dates&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&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;today&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;today&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;today&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;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&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;now&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;%Y-%m-&lt;/span&gt;&lt;span class="si"&gt;%d&lt;/span&gt;&lt;span class="s2"&gt; %H:%M:%S&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;date.today()&lt;/code&gt; for the current date and &lt;code&gt;datetime.now()&lt;/code&gt; when you also need the current time.&lt;/p&gt;</description></item><item><title>Python zip() Function Explained</title><link>https://pythonbeginner.help/reference/python-zip-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/reference/python-zip-function-explained/</guid><description>&lt;h1 id="python-zip-function-explained"&gt;Python &lt;code&gt;zip()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;zip()&lt;/code&gt; is a built-in Python function that combines items from two or more iterables by position.&lt;/p&gt;
&lt;p&gt;It is useful when you want to work with related values at the same time, such as names and scores, or keys and values. Beginners often use &lt;code&gt;zip()&lt;/code&gt; inside a &lt;code&gt;for&lt;/code&gt; loop or convert its result into a list or dictionary.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;names&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;Ana&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Ben&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Cara&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;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;85&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;88&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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scores&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&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>Raising Exceptions in Python</title><link>https://pythonbeginner.help/learn/raising-exceptions-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/raising-exceptions-in-python/</guid><description>&lt;h1 id="raising-exceptions-in-python"&gt;Raising Exceptions in Python&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;raise&lt;/code&gt; lets you stop your program and report a problem clearly.&lt;/p&gt;
&lt;p&gt;You use it when something is wrong with the data, the input, or the current state of the program. This helps you catch bugs early and makes your code easier to understand.&lt;/p&gt;
&lt;p&gt;Think of &lt;code&gt;raise&lt;/code&gt; as a way to speak up the moment something looks wrong, instead of letting bad data quietly travel deeper into your program.&lt;/p&gt;</description></item><item><title>random.choice() Function Explained</title><link>https://pythonbeginner.help/standard-library/random.choice-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/random.choice-function-explained/</guid><description>&lt;h1 id="randomchoice-function-explained"&gt;&lt;code&gt;random.choice()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;random.choice()&lt;/code&gt; lets you pick &lt;strong&gt;one random item&lt;/strong&gt; from a sequence.&lt;/p&gt;
&lt;p&gt;Use it when you want a single random value from something like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a list&lt;/li&gt;
&lt;li&gt;a tuple&lt;/li&gt;
&lt;li&gt;a string&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It returns the chosen item directly. The sequence must contain at least one item.&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;random&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;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;blue&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&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choice&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;choice&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;random.choice()&lt;/code&gt; when you want one random item from a non-empty sequence like a list, tuple, or string.&lt;/p&gt;
&lt;h2 id="what-randomchoice-does"&gt;What &lt;code&gt;random.choice()&lt;/code&gt; does &lt;a class="heading-anchor" href="#what-randomchoice-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;random.choice()&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>random.randint() Function Explained</title><link>https://pythonbeginner.help/standard-library/random.randint-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/random.randint-function-explained/</guid><description>&lt;h1 id="randomrandint-function-explained"&gt;random.randint() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;random.randint()&lt;/code&gt; gives you a random whole number between two values.&lt;/p&gt;
&lt;p&gt;It is part of Python’s &lt;code&gt;random&lt;/code&gt; module, so you must import &lt;code&gt;random&lt;/code&gt; before using it. A very important detail is that &lt;code&gt;random.randint()&lt;/code&gt; includes &lt;strong&gt;both&lt;/strong&gt; the start and end values.&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="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;random&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;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;randint&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;10&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use &lt;code&gt;random.randint(start, end)&lt;/code&gt; to get a random integer between &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt;, including both values.&lt;/p&gt;
&lt;h2 id="what-randomrandint-does"&gt;What random.randint() does &lt;a class="heading-anchor" href="#what-randomrandint-does" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;random.randint()&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>random.shuffle() Function Explained</title><link>https://pythonbeginner.help/standard-library/random.shuffle-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/random.shuffle-function-explained/</guid><description>&lt;h1 id="randomshuffle-function-explained"&gt;&lt;code&gt;random.shuffle()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;random.shuffle()&lt;/code&gt; puts the items in a list into a random order.&lt;/p&gt;
&lt;p&gt;It is important to know two things about this function:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It changes the original list&lt;/li&gt;
&lt;li&gt;It returns &lt;code&gt;None&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a common source of beginner mistakes. If you expect a new list to be returned, your code will not work the way you expect.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;random&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;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 class="mi"&gt;4&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;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shuffle&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&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&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Example output:&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>Return Values in Python Functions</title><link>https://pythonbeginner.help/learn/return-values-in-python-functions/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/return-values-in-python-functions/</guid><description>&lt;h1 id="return-values-in-python-functions"&gt;Return Values in Python Functions&lt;/h1&gt;
&lt;p&gt;A return value is the result a function sends back after it runs. Understanding this is an important step in learning how Python functions work.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;return&lt;/code&gt; statement lets a function give data back to the code that called it. You can then store that value, print it, compare it, or use it in another calculation.&lt;/p&gt;
&lt;p&gt;If a function does not use &lt;code&gt;return&lt;/code&gt;, Python gives back &lt;code&gt;None&lt;/code&gt; instead.&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>sys.argv Explained</title><link>https://pythonbeginner.help/standard-library/sys.argv-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/sys.argv-explained/</guid><description>&lt;h1 id="sysargv-explained"&gt;sys.argv Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;sys.argv&lt;/code&gt; lets a Python script read values passed from the command line.&lt;/p&gt;
&lt;p&gt;It is useful for small scripts where you want to give input when you run the file, such as a file name, a word, or a number.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;sys&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&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;# Run from terminal:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# python script.py hello 123&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;sys.argv&lt;/code&gt; is a list of command line arguments. The first item is the script name.&lt;/p&gt;</description></item><item><title>sys.exit() Function Explained</title><link>https://pythonbeginner.help/standard-library/sys.exit-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/sys.exit-function-explained/</guid><description>&lt;h1 id="sysexit-function-explained"&gt;sys.exit() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;sys.exit()&lt;/code&gt; stops a Python program early.&lt;/p&gt;
&lt;p&gt;It is part of the &lt;code&gt;sys&lt;/code&gt; module, so you must import &lt;code&gt;sys&lt;/code&gt; before using it. This function is common in scripts that need to stop after invalid input, a missing file, or a finished command-line task.&lt;/p&gt;
&lt;p&gt;A key detail is that &lt;code&gt;sys.exit()&lt;/code&gt; does not simply &amp;ldquo;shut Python down.&amp;rdquo; It raises a special exception called &lt;code&gt;SystemExit&lt;/code&gt;. That matters because &lt;code&gt;finally&lt;/code&gt; blocks still run, and code can catch &lt;code&gt;SystemExit&lt;/code&gt; if needed.&lt;/p&gt;</description></item><item><title>sys.path Explained</title><link>https://pythonbeginner.help/standard-library/sys.path-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/sys.path-explained/</guid><description>&lt;h1 id="syspath-explained"&gt;sys.path Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;sys.path&lt;/code&gt; is one of the most useful things to understand when Python imports are confusing.&lt;/p&gt;
&lt;p&gt;It tells Python &lt;strong&gt;where to look for modules and packages&lt;/strong&gt; when you use &lt;code&gt;import&lt;/code&gt;. If an import fails, or Python imports the wrong file, &lt;code&gt;sys.path&lt;/code&gt; often explains why.&lt;/p&gt;
&lt;p&gt;This page shows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what &lt;code&gt;sys.path&lt;/code&gt; is&lt;/li&gt;
&lt;li&gt;what it usually contains&lt;/li&gt;
&lt;li&gt;how Python uses it during import&lt;/li&gt;
&lt;li&gt;how to inspect it safely&lt;/li&gt;
&lt;li&gt;when changing it helps, and when it causes more problems&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-way-to-inspect-syspath"&gt;Quick way to inspect &lt;code&gt;sys.path&lt;/code&gt; &lt;a class="heading-anchor" href="#quick-way-to-inspect-syspath" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use this to see where Python is looking for modules:&lt;/p&gt;</description></item><item><title>The __init__ Method in Python Explained</title><link>https://pythonbeginner.help/learn/the-__init__-method-in-python-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/the-__init__-method-in-python-explained/</guid><description>&lt;h1 id="the-__init__-method-in-python-explained"&gt;The &lt;code&gt;__init__&lt;/code&gt; Method in Python Explained&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;__init__&lt;/code&gt; method is a special method in a Python class. It runs automatically when you create a new object.&lt;/p&gt;
&lt;p&gt;Beginners use &lt;code&gt;__init__&lt;/code&gt; to give each object its starting data. For example, if you create a &lt;code&gt;Dog&lt;/code&gt; object, &lt;code&gt;__init__&lt;/code&gt; can store its name and age right away.&lt;/p&gt;
&lt;p&gt;The sections below walk through the syntax, how object creation works, and the common mistakes to watch for.&lt;/p&gt;</description></item><item><title>time.sleep() Function Explained</title><link>https://pythonbeginner.help/standard-library/time.sleep-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/time.sleep-function-explained/</guid><description>&lt;h1 id="timesleep-function-explained"&gt;time.sleep() Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;time.sleep()&lt;/code&gt; pauses a Python program for a set amount of time.&lt;/p&gt;
&lt;p&gt;It is a simple and useful function for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;adding a delay in a script&lt;/li&gt;
&lt;li&gt;building a basic countdown&lt;/li&gt;
&lt;li&gt;spacing out repeated output&lt;/li&gt;
&lt;li&gt;practicing program flow&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This function is part of Python’s &lt;code&gt;time&lt;/code&gt; module, so you must import that module before using it.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;time&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Start&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;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;After 2 seconds&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;time.sleep(seconds)&lt;/code&gt; to pause the program. The value can be an integer like &lt;code&gt;2&lt;/code&gt; or a decimal like &lt;code&gt;0.5&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>time.time() Function Explained</title><link>https://pythonbeginner.help/standard-library/time.time-function-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/standard-library/time.time-function-explained/</guid><description>&lt;h1 id="timetime-function-explained"&gt;&lt;code&gt;time.time()&lt;/code&gt; Function Explained&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;time.time()&lt;/code&gt; returns the current time as a number.&lt;/p&gt;
&lt;p&gt;In Python, this number is the current &lt;strong&gt;Unix timestamp&lt;/strong&gt;: the number of seconds since &lt;strong&gt;January 1, 1970 UTC&lt;/strong&gt;. Beginners often use it for two simple tasks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;getting the current timestamp&lt;/li&gt;
&lt;li&gt;measuring how long some code takes to run&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want a readable date like &lt;code&gt;2025-04-22 10:30:00&lt;/code&gt;, use the &lt;a href="https://pythonbeginner.help/standard-library/python-datetime-module-overview"&gt;Python datetime module overview&lt;/a&gt; instead.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;time&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;current_timestamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;time&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;current_timestamp&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;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;time&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;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&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 class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;time&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;end&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&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;code&gt;time.time()&lt;/code&gt; returns the current time as seconds since the Unix epoch. It is often used for simple timing.&lt;/p&gt;</description></item><item><title>Type Conversion in Python (Casting Between Types)</title><link>https://pythonbeginner.help/learn/type-conversion-in-python-casting-between-types/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/type-conversion-in-python-casting-between-types/</guid><description>&lt;h1 id="type-conversion-in-python-casting-between-types"&gt;Type Conversion in Python (Casting Between Types)&lt;/h1&gt;
&lt;p&gt;Type conversion in Python means changing a value from one type to another.&lt;/p&gt;
&lt;p&gt;This is very common when working with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;user input&lt;/li&gt;
&lt;li&gt;file data&lt;/li&gt;
&lt;li&gt;numbers stored as text&lt;/li&gt;
&lt;li&gt;text messages that include numbers&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Python gives you built-in functions like &lt;code&gt;int()&lt;/code&gt;, &lt;code&gt;float()&lt;/code&gt;, &lt;code&gt;str()&lt;/code&gt;, and &lt;code&gt;bool()&lt;/code&gt; to do this. Beginners often call this &lt;strong&gt;casting&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll go through each of these conversion functions, when you need them, and how to handle values that won&amp;rsquo;t convert cleanly.&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>Understanding Python Statements and Expressions</title><link>https://pythonbeginner.help/learn/understanding-python-statements-and-expressions/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/understanding-python-statements-and-expressions/</guid><description>&lt;h1 id="understanding-python-statements-and-expressions"&gt;Understanding Python Statements and Expressions&lt;/h1&gt;
&lt;p&gt;When you start learning Python, you will see terms like &lt;strong&gt;statement&lt;/strong&gt; and &lt;strong&gt;expression&lt;/strong&gt;. These words sound technical, but the idea is simple.&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;statement&lt;/strong&gt; is code that tells Python to do something.&lt;/p&gt;
&lt;p&gt;An &lt;strong&gt;expression&lt;/strong&gt; is code that Python evaluates to a value.&lt;/p&gt;
&lt;p&gt;You will often see both working together in the same line of code. Once you understand that, beginner code becomes much easier to read.&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>Using try, except, else, and finally in Python</title><link>https://pythonbeginner.help/learn/using-try-except-else-and-finally-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/using-try-except-else-and-finally-in-python/</guid><description>&lt;h1 id="using-try-except-else-and-finally-in-python"&gt;Using try, except, else, and finally in Python&lt;/h1&gt;
&lt;p&gt;Learn how Python exception handling blocks work together so you can catch errors, run code only when no error happens, and always clean up resources.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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="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&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 whole number.&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;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;finally&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;Program finished.&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;figure class="diagram" role="group" aria-label="else runs only on success; finally always runs."&gt;
&lt;svg width="596" height="271" viewBox="0 0 596 271" class="d-svg" xmlns="http://www.w3.org/2000/svg" role="img"&gt;
 &lt;defs&gt;&lt;marker id="flowarrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"&gt;&lt;path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/&gt;&lt;/marker&gt;&lt;/defs&gt;&lt;rect x="178" y="8" width="245" height="44" rx="8" class="d-node-try"/&gt;
 &lt;text x="300" y="30" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;try: int(input(...))&lt;/text&gt;&lt;path d="M178 30 H142 V110" class="d-edge" marker-end="url(#flowarrow)" fill="none"/&gt;
 &lt;text x="190" y="72" class="d-edge-label d-edge-ok"&gt;no error&lt;/text&gt;
 &lt;path d="M422 30 H457 V110" class="d-edge" marker-end="url(#flowarrow)" fill="none"/&gt;
 &lt;text x="370" y="72" class="d-edge-label d-edge-err"&gt;error raised&lt;/text&gt;&lt;rect x="20" y="110" width="245" height="44" rx="8" class="d-node"/&gt;
 &lt;text x="142" y="132" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;else: print the number&lt;/text&gt;&lt;rect x="335" y="110" width="245" height="44" rx="8" class="d-node-err"/&gt;
 &lt;text x="457" y="132" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;except: invalid number message&lt;/text&gt;&lt;path d="M142 154 V215 H300" class="d-edge" fill="none"/&gt;
 &lt;path d="M457 154 V215 H300" class="d-edge" fill="none"/&gt;
 &lt;line x1="300" y1="215" x2="300" y2="216" class="d-edge" marker-end="url(#flowarrow)"/&gt;
 &lt;rect x="178" y="215" width="245" height="44" rx="8" class="d-node-fin"/&gt;
 &lt;text x="300" y="237" class="d-flow-txt" dominant-baseline="central" text-anchor="middle"&gt;finally: print &amp;#39;Program finished.&amp;#39;&lt;/text&gt;&lt;/svg&gt;&lt;figcaption&gt;else runs only on success; finally always runs.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Use &lt;code&gt;try&lt;/code&gt; for risky code, &lt;code&gt;except&lt;/code&gt; for handling specific errors, &lt;code&gt;else&lt;/code&gt; for success-only code, and &lt;code&gt;finally&lt;/code&gt; for cleanup code that must always run.&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>What Is a Boolean in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-boolean-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-boolean-in-python/</guid><description>&lt;h1 id="what-is-a-boolean-in-python"&gt;What Is a Boolean in Python?&lt;/h1&gt;
&lt;p&gt;A Boolean in Python is a value that can only be &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Beginners see Booleans very early because Python uses them to make decisions. For example, a program might check whether a user is logged in, whether a number is greater than another number, or whether a list has any items.&lt;/p&gt;
&lt;p&gt;If you are new to Python, this page will help you understand what Booleans are, where they come from, and how they are used in simple &lt;code&gt;if&lt;/code&gt; statements.&lt;/p&gt;</description></item><item><title>What Is a Class in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-class-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-class-in-python/</guid><description>&lt;h1 id="what-is-a-class-in-python"&gt;What Is a Class in Python?&lt;/h1&gt;
&lt;p&gt;A class in Python is a blueprint for creating objects.&lt;/p&gt;
&lt;p&gt;If that sounds abstract, think of it this way:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A class describes what something has&lt;/li&gt;
&lt;li&gt;A class also describes what something can do&lt;/li&gt;
&lt;li&gt;The actual thing you create from that description is called an object&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Classes help you group data and behavior in one place. In Python, the data is usually stored in &lt;strong&gt;attributes&lt;/strong&gt;, and the actions are defined with &lt;strong&gt;methods&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>What Is a Data Type in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-data-type-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-data-type-in-python/</guid><description>&lt;h1 id="what-is-a-data-type-in-python"&gt;What Is a Data Type in Python?&lt;/h1&gt;
&lt;p&gt;A data type in Python tells Python what kind of value you are working with.&lt;/p&gt;
&lt;p&gt;For example, a value might be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;text&lt;/li&gt;
&lt;li&gt;a whole number&lt;/li&gt;
&lt;li&gt;a decimal number&lt;/li&gt;
&lt;li&gt;&lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Data types matter because they affect what you can do with a value. Python uses them to decide how values are stored and how operations should behave.&lt;/p&gt;
&lt;h2 id="what-a-data-type-means"&gt;What a data type means &lt;a class="heading-anchor" href="#what-a-data-type-means" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A data type describes the kind of value you are using.&lt;/p&gt;</description></item><item><title>What Is a Dictionary in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-dictionary-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-dictionary-in-python/</guid><description>&lt;h1 id="what-is-a-dictionary-in-python"&gt;What Is a Dictionary in Python?&lt;/h1&gt;
&lt;p&gt;A dictionary in Python is a way to store related data using &lt;strong&gt;keys&lt;/strong&gt; and &lt;strong&gt;values&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This is useful when your data has labels. For example, a person can have a &lt;strong&gt;name&lt;/strong&gt;, &lt;strong&gt;age&lt;/strong&gt;, and &lt;strong&gt;city&lt;/strong&gt;. Instead of storing those values by position, a dictionary stores them by name.&lt;/p&gt;
&lt;p&gt;This page explains the basic idea of a dictionary, what it stores, and when to use one.&lt;/p&gt;</description></item><item><title>What Is a Float in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-float-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-float-in-python/</guid><description>&lt;h1 id="what-is-a-float-in-python"&gt;What Is a Float in Python?&lt;/h1&gt;
&lt;p&gt;A &lt;strong&gt;float&lt;/strong&gt; in Python is a number that can include a decimal point. Beginners often use floats for values like &lt;code&gt;3.14&lt;/code&gt;, &lt;code&gt;2.5&lt;/code&gt;, or &lt;code&gt;-0.75&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Floats are useful when you need numbers that are not just whole numbers. For example, you might use them for measurements, prices in simple examples, or division results.&lt;/p&gt;
&lt;p&gt;This page explains what the term &lt;strong&gt;float&lt;/strong&gt; means, how it looks in Python, and how it differs from an integer.&lt;/p&gt;</description></item><item><title>What Is a Function in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-function-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-function-in-python/</guid><description>&lt;h1 id="what-is-a-function-in-python"&gt;What Is a Function in Python?&lt;/h1&gt;
&lt;p&gt;A function in Python is a reusable block of code that does a specific task. You can run it when needed, and it can optionally send a value back.&lt;/p&gt;
&lt;p&gt;Functions are one of the main ways to organize code. They help you group related steps together and avoid writing the same code again and again.&lt;/p&gt;
&lt;h2 id="simple-definition"&gt;Simple definition &lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A function is:&lt;/p&gt;</description></item><item><title>What Is a Generator in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-generator-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-generator-in-python/</guid><description>&lt;h1 id="what-is-a-generator-in-python"&gt;What Is a Generator in Python?&lt;/h1&gt;
&lt;p&gt;A generator in Python is an object that produces values one at a time, only when they are needed.&lt;/p&gt;
&lt;p&gt;This is useful because Python does not have to create and store every value at once. For beginners, the main idea is simple: a generator lets you work through data step by step instead of building a full list immediately.&lt;/p&gt;
&lt;p&gt;Generators are commonly created with a function that uses &lt;code&gt;yield&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>What Is a Lambda Function in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-lambda-function-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-lambda-function-in-python/</guid><description>&lt;h1 id="what-is-a-lambda-function-in-python"&gt;What Is a Lambda Function in Python?&lt;/h1&gt;
&lt;p&gt;A lambda function in Python is a small function written in one line.&lt;/p&gt;
&lt;p&gt;Beginners usually see lambda functions in examples with sorting, &lt;code&gt;map()&lt;/code&gt;, or &lt;code&gt;filter()&lt;/code&gt;. They are useful for short tasks, but they are not a replacement for normal functions.&lt;/p&gt;
&lt;p&gt;A lambda function works like a regular function. The main difference is that it is written in a shorter form.&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;square&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;x&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;square&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;Output:&lt;/p&gt;</description></item><item><title>What Is a List Comprehension in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-list-comprehension-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-list-comprehension-in-python/</guid><description>&lt;h1 id="what-is-a-list-comprehension-in-python"&gt;What Is a List Comprehension in Python?&lt;/h1&gt;
&lt;p&gt;A list comprehension is a short, readable way to create a new list in Python.&lt;/p&gt;
&lt;p&gt;It lets you combine a loop and the value you want to build inside square brackets. Beginners often use it to transform data, such as squaring numbers, or to filter data, such as keeping only even numbers.&lt;/p&gt;
&lt;p&gt;Here is a simple example:&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;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 class="mi"&gt;4&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;squares&lt;/span&gt; &lt;span class="o"&gt;=&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="n"&gt;n&lt;/span&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;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;squares&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="c1"&gt;# [1, 4, 9, 16]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A list comprehension creates a new list in one line from another iterable.&lt;/p&gt;</description></item><item><title>What Is a List in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-list-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-list-in-python/</guid><description>&lt;h1 id="what-is-a-list-in-python"&gt;What Is a List in Python?&lt;/h1&gt;
&lt;p&gt;A list in Python is a beginner-friendly way to store multiple values in one variable. This page explains what a list is, what it is used for, and how to recognize one when you see it.&lt;/p&gt;
&lt;p&gt;If you are just getting started, the main idea is simple: a list lets you keep related items together in order. For example, you might use a list for names, scores, or file paths.&lt;/p&gt;</description></item><item><title>What Is a Loop in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-loop-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-loop-in-python/</guid><description>&lt;h1 id="what-is-a-loop-in-python"&gt;What Is a Loop in Python?&lt;/h1&gt;
&lt;p&gt;A loop in Python is a way to repeat code.&lt;/p&gt;
&lt;p&gt;This is useful when you want to do the same task more than once. Instead of writing the same line again and again, you can write a loop once and let Python repeat it for you.&lt;/p&gt;
&lt;p&gt;Python mainly has two loop types:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;for&lt;/code&gt; loops&lt;/li&gt;
&lt;li&gt;&lt;code&gt;while&lt;/code&gt; loops&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page gives the basic idea of loops. It does not fully teach loop syntax.&lt;/p&gt;</description></item><item><title>What Is a Method in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-method-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-method-in-python/</guid><description>&lt;h1 id="what-is-a-method-in-python"&gt;What Is a Method in Python?&lt;/h1&gt;
&lt;p&gt;A method in Python is a function that belongs to an object.&lt;/p&gt;
&lt;p&gt;You use methods all the time in Python, even in simple code like:&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Ada&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="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;upper&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 example, &lt;code&gt;upper()&lt;/code&gt; is a method of a string object.&lt;/p&gt;
&lt;p&gt;Understanding methods helps you read Python code more easily. It also helps you know why some actions are written as &lt;code&gt;object.method()&lt;/code&gt; while others are written as regular functions like &lt;code&gt;len(object)&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>What Is a Module in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-module-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-module-in-python/</guid><description>&lt;h1 id="what-is-a-module-in-python"&gt;What Is a Module in Python?&lt;/h1&gt;
&lt;p&gt;A &lt;strong&gt;module&lt;/strong&gt; in Python is a file that contains code you can reuse.&lt;/p&gt;
&lt;p&gt;That file can contain:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;functions&lt;/li&gt;
&lt;li&gt;variables&lt;/li&gt;
&lt;li&gt;classes&lt;/li&gt;
&lt;li&gt;import statements&lt;/li&gt;
&lt;li&gt;code that runs when the file is imported or executed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You use a module by &lt;strong&gt;importing&lt;/strong&gt; it into another Python file.&lt;/p&gt;
&lt;p&gt;A simple way to think about it is this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;one file stores useful code&lt;/li&gt;
&lt;li&gt;another file uses that code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This page explains what a module is and why it matters. If you want the full mechanics of &lt;code&gt;import&lt;/code&gt;, see &lt;a href="https://pythonbeginner.help/learn/how-import-works-in-python/"&gt;how import works in Python&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>What Is a Package in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-package-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-package-in-python/</guid><description>&lt;h1 id="what-is-a-package-in-python"&gt;What Is a Package in Python?&lt;/h1&gt;
&lt;p&gt;A &lt;strong&gt;package&lt;/strong&gt; in Python is a way to organize related code.&lt;br&gt;
In simple terms, a package is usually a &lt;strong&gt;folder&lt;/strong&gt; that contains Python modules and sometimes other package folders.&lt;/p&gt;
&lt;p&gt;This helps keep code grouped in a clear structure instead of putting everything into one large file.&lt;/p&gt;
&lt;p&gt;Beginners often use packages before they know the term. For example, when you write an &lt;code&gt;import&lt;/code&gt; statement, you may already be using a module that belongs to a package.&lt;/p&gt;</description></item><item><title>What Is a Parameter in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-parameter-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-parameter-in-python/</guid><description>&lt;h1 id="what-is-a-parameter-in-python"&gt;What Is a Parameter in Python?&lt;/h1&gt;
&lt;p&gt;A &lt;strong&gt;parameter&lt;/strong&gt; in Python is a variable written inside the parentheses of a function definition.&lt;/p&gt;
&lt;p&gt;It acts like a placeholder. When you call the function later, Python gives that parameter a value.&lt;/p&gt;
&lt;p&gt;This page focuses on the basic idea:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what a parameter is&lt;/li&gt;
&lt;li&gt;where it appears&lt;/li&gt;
&lt;li&gt;how it is different from an argument&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is not a full guide to writing functions. If you want the bigger picture, see &lt;a href="https://pythonbeginner.help/learn/python-functions-explained/"&gt;Python Functions Explained&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>What Is a Return Value in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-return-value-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-return-value-in-python/</guid><description>&lt;h1 id="what-is-a-return-value-in-python"&gt;What Is a Return Value in Python?&lt;/h1&gt;
&lt;p&gt;A &lt;strong&gt;return value&lt;/strong&gt; is the result a function sends back after it finishes running.&lt;/p&gt;
&lt;p&gt;This is an important Python idea because functions often do work and then give the answer back to the code that called them. A beginner mistake is thinking that &lt;code&gt;print()&lt;/code&gt; and &lt;code&gt;return&lt;/code&gt; do the same thing. They do not.&lt;/p&gt;
&lt;p&gt;Use &lt;code&gt;return&lt;/code&gt; when a function should give a result back to your program:&lt;/p&gt;</description></item><item><title>What Is a Set in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-set-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-set-in-python/</guid><description>&lt;h1 id="what-is-a-set-in-python"&gt;What Is a Set in Python?&lt;/h1&gt;
&lt;p&gt;A set in Python is a collection of unique values. This page helps beginners understand what a set is, when to use it, and how it is different from other collection types.&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;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 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&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;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;set&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;blue&amp;#34;&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&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&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;
&lt;ul&gt;
&lt;li&gt;The first line creates a set with duplicate &lt;code&gt;3&lt;/code&gt;, but the duplicate is removed.&lt;/li&gt;
&lt;li&gt;The second example uses &lt;code&gt;set()&lt;/code&gt; to convert a list into a set.&lt;/li&gt;
&lt;li&gt;In both cases, only unique values remain.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Possible output:&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>What Is a String in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-string-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-string-in-python/</guid><description>&lt;h1 id="what-is-a-string-in-python"&gt;What Is a String in Python?&lt;/h1&gt;
&lt;p&gt;A string in Python is a value used to store text.&lt;/p&gt;
&lt;p&gt;Beginners use strings all the time. A string can hold:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A word&lt;/li&gt;
&lt;li&gt;A sentence&lt;/li&gt;
&lt;li&gt;A number written as text&lt;/li&gt;
&lt;li&gt;Even empty text like &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Python knows something is a string when it is written inside quotes. This page defines the term clearly and shows where strings are commonly used.&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;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="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Hello&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="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 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;Output:&lt;/p&gt;</description></item><item><title>What Is a Tuple in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-tuple-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-tuple-in-python/</guid><description>&lt;h1 id="what-is-a-tuple-in-python"&gt;What Is a Tuple in Python?&lt;/h1&gt;
&lt;p&gt;A tuple in Python is a way to store multiple values in a single variable.&lt;/p&gt;
&lt;p&gt;Tuples are &lt;strong&gt;ordered collections&lt;/strong&gt;, which means the items stay in the same position. They are usually used for data that should not change after it is created.&lt;/p&gt;
&lt;p&gt;You will often see tuples written with parentheses, 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="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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you want a deeper lesson, see &lt;a href="https://pythonbeginner.help/learn/python-tuples-explained/"&gt;Python tuples explained&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="simple-definition"&gt;Simple definition &lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A tuple is a collection of values stored together.&lt;/p&gt;</description></item><item><title>What Is a Variable in Python?</title><link>https://pythonbeginner.help/glossary/what-is-a-variable-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-a-variable-in-python/</guid><description>&lt;h1 id="what-is-a-variable-in-python"&gt;What Is a Variable in Python?&lt;/h1&gt;
&lt;p&gt;A variable in Python is a name that refers to a value.&lt;/p&gt;
&lt;p&gt;You use variables to store data and use it later in your code. For example, you can store a person&amp;rsquo;s name, an age, a price, or a &lt;code&gt;True&lt;/code&gt;/&lt;code&gt;False&lt;/code&gt; value in a variable.&lt;/p&gt;
&lt;p&gt;In Python, you create a variable by assigning a value with &lt;code&gt;=&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;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="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&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="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 class="nb"&gt;print&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;/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="n"&gt;Sam&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="mi"&gt;12&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In this example:&lt;/p&gt;</description></item><item><title>What Is an Argument in Python?</title><link>https://pythonbeginner.help/glossary/what-is-an-argument-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-an-argument-in-python/</guid><description>&lt;h1 id="what-is-an-argument-in-python"&gt;What Is an Argument in Python?&lt;/h1&gt;
&lt;p&gt;An &lt;strong&gt;argument&lt;/strong&gt; in Python is a value you pass to a function when you call it.&lt;/p&gt;
&lt;p&gt;This helps the function work with real data. For example, a function can greet different people, add different numbers, or print different messages based on the arguments you give it.&lt;/p&gt;
&lt;p&gt;A common beginner confusion is the difference between &lt;strong&gt;arguments&lt;/strong&gt; and &lt;strong&gt;parameters&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Parameters&lt;/strong&gt; are the names written in the function definition.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Arguments&lt;/strong&gt; are the actual values passed into the function call.&lt;/li&gt;
&lt;/ul&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&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;&amp;quot;Sam&amp;quot;&lt;/code&gt; is the &lt;strong&gt;argument&lt;/strong&gt;. It is the value passed to the function.&lt;/p&gt;</description></item><item><title>What Is an Exception in Python?</title><link>https://pythonbeginner.help/glossary/what-is-an-exception-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-an-exception-in-python/</guid><description>&lt;h1 id="what-is-an-exception-in-python"&gt;What Is an Exception in Python?&lt;/h1&gt;
&lt;p&gt;An exception in Python is a problem that happens &lt;strong&gt;while your program is running&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;When an exception happens, Python usually stops the normal flow of the program and shows an error message. In many cases, you can also &lt;strong&gt;handle&lt;/strong&gt; the exception so your program responds in a better way instead of crashing.&lt;/p&gt;
&lt;p&gt;A simple way to think about it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Your code starts running normally&lt;/li&gt;
&lt;li&gt;Something unexpected happens&lt;/li&gt;
&lt;li&gt;Python raises an exception&lt;/li&gt;
&lt;li&gt;You can either let it stop the program or handle it with &lt;code&gt;try&lt;/code&gt; and &lt;code&gt;except&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="a-quick-example"&gt;A quick example &lt;a class="heading-anchor" href="#a-quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Here is a small example of an exception being handled:&lt;/p&gt;</description></item><item><title>What Is an if Statement in Python?</title><link>https://pythonbeginner.help/glossary/what-is-an-if-statement-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-an-if-statement-in-python/</guid><description>&lt;h1 id="what-is-an-if-statement-in-python"&gt;What Is an if Statement in Python?&lt;/h1&gt;
&lt;p&gt;An &lt;code&gt;if&lt;/code&gt; statement in Python lets your program make a decision.&lt;/p&gt;
&lt;p&gt;It checks a condition. If that condition is &lt;code&gt;True&lt;/code&gt;, Python runs the code inside the &lt;code&gt;if&lt;/code&gt; block. If the condition is &lt;code&gt;False&lt;/code&gt;, Python skips that code.&lt;/p&gt;
&lt;p&gt;This is one of the most important ideas in Python because it helps programs respond to different situations.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;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="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;You can vote&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;Output:&lt;/p&gt;</description></item><item><title>What Is an Integer in Python?</title><link>https://pythonbeginner.help/glossary/what-is-an-integer-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-an-integer-in-python/</guid><description>&lt;h1 id="what-is-an-integer-in-python"&gt;What Is an Integer in Python?&lt;/h1&gt;
&lt;p&gt;An integer in Python is a whole number. It does not have a decimal point.&lt;/p&gt;
&lt;p&gt;Examples of integers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-3&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;7&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;42&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In Python, the type name for an integer is &lt;code&gt;int&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you are new to Python, integers are one of the most common &lt;a href="https://pythonbeginner.help/glossary/what-is-a-data-type-in-python/"&gt;data types in Python&lt;/a&gt;. You will use them for counting, indexing, loops, and simple math.&lt;/p&gt;
&lt;h2 id="definition"&gt;Definition &lt;a class="heading-anchor" href="#definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;An integer is:&lt;/p&gt;</description></item><item><title>What Is an Iterable in Python?</title><link>https://pythonbeginner.help/glossary/what-is-an-iterable-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-an-iterable-in-python/</guid><description>&lt;h1 id="what-is-an-iterable-in-python"&gt;What Is an Iterable in Python?&lt;/h1&gt;
&lt;p&gt;An &lt;strong&gt;iterable&lt;/strong&gt; is an object that Python can go through one value at a time.&lt;/p&gt;
&lt;p&gt;You will see iterables all the time in Python. They are used in &lt;code&gt;for&lt;/code&gt; loops, in built-in functions like &lt;code&gt;sum()&lt;/code&gt; and &lt;code&gt;sorted()&lt;/code&gt;, and in many common tasks such as reading files or unpacking values.&lt;/p&gt;
&lt;p&gt;A big reason beginners should learn this word is that many errors and examples make more sense once you know what an iterable is. It also helps you understand the difference between an &lt;strong&gt;iterable&lt;/strong&gt; and an &lt;strong&gt;iterator&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>What Is an Iterator in Python?</title><link>https://pythonbeginner.help/glossary/what-is-an-iterator-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-an-iterator-in-python/</guid><description>&lt;h1 id="what-is-an-iterator-in-python"&gt;What Is an Iterator in Python?&lt;/h1&gt;
&lt;p&gt;An iterator in Python is an object that gives you values &lt;strong&gt;one at a time&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It keeps track of where it is, so each time you ask for the next value, it moves forward. Iterators are used behind the scenes in &lt;code&gt;for&lt;/code&gt; loops, and they are closely related to &lt;a href="https://pythonbeginner.help/glossary/what-is-an-iterable-in-python/"&gt;iterable objects&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A beginner-friendly way to think about it is this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An &lt;strong&gt;iterable&lt;/strong&gt; is something you can loop over&lt;/li&gt;
&lt;li&gt;An &lt;strong&gt;iterator&lt;/strong&gt; is the thing that actually returns each item one by one&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" 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;it&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;iter&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&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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&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="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&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="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&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>What Is an Object in Python?</title><link>https://pythonbeginner.help/glossary/what-is-an-object-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-an-object-in-python/</guid><description>&lt;h1 id="what-is-an-object-in-python"&gt;What Is an Object in Python?&lt;/h1&gt;
&lt;p&gt;In Python, an &lt;strong&gt;object&lt;/strong&gt; is a value that exists in memory.&lt;/p&gt;
&lt;p&gt;This idea is important because &lt;strong&gt;everything you work with in Python is an object&lt;/strong&gt;. That includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;numbers&lt;/li&gt;
&lt;li&gt;strings&lt;/li&gt;
&lt;li&gt;lists&lt;/li&gt;
&lt;li&gt;dictionaries&lt;/li&gt;
&lt;li&gt;booleans&lt;/li&gt;
&lt;li&gt;functions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you understand what an object is, it becomes easier to understand types, methods, and some common errors.&lt;/p&gt;
&lt;h2 id="quick-example"&gt;Quick example &lt;a class="heading-anchor" href="#quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A quick way to see that different values in Python are objects with different types:&lt;/p&gt;</description></item><item><title>What Is Error Handling in Python?</title><link>https://pythonbeginner.help/glossary/what-is-error-handling-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-error-handling-in-python/</guid><description>&lt;h1 id="what-is-error-handling-in-python"&gt;What Is Error Handling in Python?&lt;/h1&gt;
&lt;p&gt;Error handling is the way a Python program deals with problems while it is running.&lt;/p&gt;
&lt;p&gt;Instead of crashing as soon as something goes wrong, your code can respond in a controlled way. This is useful when working with user input, files, calculations, and other data that may not always be valid.&lt;/p&gt;
&lt;p&gt;In Python, error handling is commonly done with &lt;code&gt;try&lt;/code&gt; and &lt;code&gt;except&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="a-quick-example"&gt;A quick example &lt;a class="heading-anchor" href="#a-quick-example" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Here is a simple example of error handling:&lt;/p&gt;</description></item><item><title>What Is Inheritance in Python?</title><link>https://pythonbeginner.help/glossary/what-is-inheritance-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-inheritance-in-python/</guid><description>&lt;h1 id="what-is-inheritance-in-python"&gt;What Is Inheritance in Python?&lt;/h1&gt;
&lt;p&gt;Inheritance in Python is a way for one class to use code from another class.&lt;/p&gt;
&lt;p&gt;This helps you reuse methods and attributes instead of writing the same code again. It is a common idea in object-oriented programming, so it makes more sense if you already understand &lt;a href="https://pythonbeginner.help/learn/python-classes-and-objects-explained"&gt;classes and objects in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here is the basic idea:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&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;def&lt;/span&gt; &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&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="s2"&gt;&amp;#34;Some sound&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;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Animal&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;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;pet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Dog&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;pet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;speak&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>What Is Python? A Beginner-Friendly Introduction</title><link>https://pythonbeginner.help/learn/what-is-python-a-beginner-friendly-introduction/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/what-is-python-a-beginner-friendly-introduction/</guid><description>&lt;h1 id="what-is-python-a-beginner-friendly-introduction"&gt;What Is Python? A Beginner-Friendly Introduction&lt;/h1&gt;
&lt;p&gt;Python is a beginner-friendly programming language used for many real tasks.&lt;/p&gt;
&lt;p&gt;This page explains what Python is, why people use it, what makes it beginner-friendly, and what to learn next. If you are new to programming, this is a good place to start before moving on to installation, running code, and basic syntax.&lt;/p&gt;
&lt;h2 id="what-python-is"&gt;What Python is &lt;a class="heading-anchor" href="#what-python-is" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python is a &lt;strong&gt;programming language&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>What Is Recursion in Python?</title><link>https://pythonbeginner.help/glossary/what-is-recursion-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/glossary/what-is-recursion-in-python/</guid><description>&lt;h1 id="what-is-recursion-in-python"&gt;What Is Recursion in Python?&lt;/h1&gt;
&lt;p&gt;Recursion in Python means a function calls itself.&lt;/p&gt;
&lt;p&gt;This may sound strange at first, but the idea is simple: the function keeps solving a smaller version of the same problem until it reaches a stopping point.&lt;/p&gt;
&lt;p&gt;A recursive function has two main parts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Base case&lt;/strong&gt;: the condition that stops the function&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recursive case&lt;/strong&gt;: the part where the function calls itself again&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is the simplest working example:&lt;/p&gt;</description></item><item><title>When to Use Lists vs Tuples vs Sets vs Dictionaries</title><link>https://pythonbeginner.help/learn/when-to-use-lists-vs-tuples-vs-sets-vs-dictionaries/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/when-to-use-lists-vs-tuples-vs-sets-vs-dictionaries/</guid><description>&lt;h1 id="when-to-use-lists-vs-tuples-vs-sets-vs-dictionaries"&gt;When to Use Lists vs Tuples vs Sets vs Dictionaries&lt;/h1&gt;
&lt;p&gt;Choosing the right Python collection type is easier when you focus on how the data will be used.&lt;/p&gt;
&lt;p&gt;This page helps you decide between:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;lists&lt;/strong&gt; for ordered items you may change&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;tuples&lt;/strong&gt; for ordered data that should stay fixed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;sets&lt;/strong&gt; for unique values&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;dictionaries&lt;/strong&gt; for key-value pairs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are new to Python, it is common to use a list for everything at first. But Python gives you different collection types because they solve different problems.&lt;/p&gt;</description></item><item><title>Why Learn Python? Use Cases and Benefits</title><link>https://pythonbeginner.help/learn/why-learn-python-use-cases-and-benefits/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/why-learn-python-use-cases-and-benefits/</guid><description>&lt;h1 id="why-learn-python-use-cases-and-benefits"&gt;Why Learn Python? Use Cases and Benefits&lt;/h1&gt;
&lt;p&gt;Python is one of the most popular programming languages in the world. For beginners, that matters because it usually means two things: it is practical, and it is easier to get help when you get stuck.&lt;/p&gt;
&lt;p&gt;This page explains why people learn Python, what it is commonly used for, and whether it is a good first language for you. The goal is not to teach Python syntax yet. The goal is to help you decide if Python is worth learning.&lt;/p&gt;</description></item><item><title>Working with File Paths in Python</title><link>https://pythonbeginner.help/learn/working-with-file-paths-in-python/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/working-with-file-paths-in-python/</guid><description>&lt;h1 id="working-with-file-paths-in-python"&gt;Working with File Paths in Python&lt;/h1&gt;
&lt;p&gt;A file path tells Python where a file or folder is located.&lt;/p&gt;
&lt;p&gt;When you read, write, rename, or delete files, Python needs a path. This page shows what file paths are, how relative and absolute paths work, and the safest beginner-friendly way to build paths in Python.&lt;/p&gt;
&lt;p&gt;Getting paths right is what stops your code from breaking when it runs on a different computer or from a different folder.&lt;/p&gt;</description></item><item><title>Your First Python Program: Hello World Explained</title><link>https://pythonbeginner.help/learn/your-first-python-program-hello-world-explained/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/your-first-python-program-hello-world-explained/</guid><description>&lt;h1 id="your-first-python-program-hello-world-explained"&gt;Your First Python Program: Hello World Explained&lt;/h1&gt;
&lt;p&gt;Writing a &lt;strong&gt;Hello World&lt;/strong&gt; program is a common first step when learning Python. It helps you confirm that Python is installed, shows you how to run code, and introduces the idea that a program is just a set of instructions for the computer.&lt;/p&gt;
&lt;p&gt;If you are completely new to Python, this is the right place to start.&lt;/p&gt;
&lt;h2 id="quick-start"&gt;Quick start &lt;a class="heading-anchor" href="#quick-start" 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="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Hello, world!&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;Save this in a &lt;code&gt;.py&lt;/code&gt; file or run it in the Python interpreter to print text to the screen.&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><item><title>Part 1: Start here</title><link>https://pythonbeginner.help/learn/part-1/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/part-1/</guid><description>&lt;p&gt;What Python is, why it&amp;rsquo;s worth learning, and getting your first program running.&lt;/p&gt;</description></item><item><title>Part 10: Going further</title><link>https://pythonbeginner.help/learn/part-10/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/part-10/</guid><description>&lt;p&gt;Powerful, slightly more advanced tools once the basics feel comfortable.&lt;/p&gt;</description></item><item><title>Part 2: Foundations</title><link>https://pythonbeginner.help/learn/part-2/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/part-2/</guid><description>&lt;p&gt;The basic rules of how Python code is written and read.&lt;/p&gt;</description></item><item><title>Part 3: Variables and types</title><link>https://pythonbeginner.help/learn/part-3/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/part-3/</guid><description>&lt;p&gt;Storing data and the basic kinds of values Python works with.&lt;/p&gt;</description></item><item><title>Part 4: Collections</title><link>https://pythonbeginner.help/learn/part-4/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/part-4/</guid><description>&lt;p&gt;Grouping many values together with lists, tuples, sets, and dictionaries.&lt;/p&gt;</description></item><item><title>Part 5: Control flow</title><link>https://pythonbeginner.help/learn/part-5/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/part-5/</guid><description>&lt;p&gt;Making decisions and repeating work so programs can react and loop.&lt;/p&gt;</description></item><item><title>Part 6: Functions</title><link>https://pythonbeginner.help/learn/part-6/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/part-6/</guid><description>&lt;p&gt;Packaging code into reusable, named blocks that take input and return results.&lt;/p&gt;</description></item><item><title>Part 7: Errors and exceptions</title><link>https://pythonbeginner.help/learn/part-7/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/part-7/</guid><description>&lt;p&gt;Understanding error messages and handling them so programs don&amp;rsquo;t just crash.&lt;/p&gt;</description></item><item><title>Part 8: Files, modules, and packages</title><link>https://pythonbeginner.help/learn/part-8/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/part-8/</guid><description>&lt;p&gt;Reading and writing files, and splitting code across modules you can import.&lt;/p&gt;</description></item><item><title>Part 9: Object-oriented programming</title><link>https://pythonbeginner.help/learn/part-9/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pythonbeginner.help/learn/part-9/</guid><description>&lt;p&gt;Modelling things as objects with their own data and behaviour.&lt;/p&gt;</description></item></channel></rss>