<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:gd="http://schemas.google.com/g/2005" xmlns:georss="http://www.georss.org/georss" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0"><id>tag:blogger.com,1999:blog-4427171222356646557</id><updated>2024-11-08T21:05:35.694+05:30</updated><category term="python"/><category term="Strings"/><category term="modules"/><category term="Functions"/><category term="Inheritance"/><category term="class"/><category term="exceptions"/><category term="Basics"/><category term="Deep Copy"/><category term="Files"/><category term="Generator"/><category term="Iterator"/><category term="Lambda"/><category term="Numpy"/><category term="RegEx"/><category term="Shallow copy"/><category term="database"/><category term="dictionary"/><category term="errors"/><category term="installation"/><category term="introduction"/><category term="mysql"/><category term="object"/><category term="pandas"/><category term="pip"/><category term="virtual environment"/><category term="win10toast"/><title type="text">Python Blog</title><subtitle type="html"/><link href="https://pythonbegginer.blogspot.com/feeds/posts/default" rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/" rel="alternate" type="text/html"/><link href="http://pubsubhubbub.appspot.com/" rel="hub"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><generator uri="http://www.blogger.com" version="7.00">Blogger</generator><openSearch:totalResults>25</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-8335681092782863126</id><published>2020-09-11T12:50:00.003+05:30</published><updated>2020-09-11T12:50:20.305+05:30</updated><title type="text">Amazon links to buy - Amazon affliate</title><content type="html">&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4 style="text-align: left;"&gt;&lt;span style="font-size: medium;"&gt; Rokali from kitchen&amp;nbsp;&lt;/span&gt;&lt;/h4&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-in.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&amp;amp;OneJS=1&amp;amp;Operation=GetAdHtml&amp;amp;MarketPlace=IN&amp;amp;source=ss&amp;amp;ref=as_ss_li_til&amp;amp;ad_type=product_link&amp;amp;tracking_id=sairambalu06-21&amp;amp;marketplace=amazon&amp;amp;region=IN&amp;amp;placement=B07JP3WPCG&amp;amp;asins=B07JP3WPCG&amp;amp;linkId=dc281202da55f685f01f1bc857ec1a83&amp;amp;show_border=true&amp;amp;link_opens_in_new_window=true" style="height: 240px; width: 120px;"&gt;&lt;/iframe&gt;&lt;/div&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/8335681092782863126/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/09/amazon-links-to-buy-amazon-affliate.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/8335681092782863126" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/8335681092782863126" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/09/amazon-links-to-buy-amazon-affliate.html" rel="alternate" title="Amazon links to buy - Amazon affliate" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-6711098076220302257</id><published>2020-07-08T11:57:00.003+05:30</published><updated>2020-07-08T15:28:00.814+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Numpy"/><title type="text">NumPy Quick tutorial - Letsprogram</title><content type="html">&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white;"&gt;NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of non-negative integers. In NumPy, dimensions are called&amp;nbsp;&lt;/span&gt;&lt;em style="background-color: white;"&gt;axes&lt;/em&gt;&lt;span style="background-color: white;"&gt;.&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;font face="arial"&gt;For example, you can create an array from a regular Python list or tuple using the &lt;/font&gt;&lt;font face="courier"&gt;array&lt;/font&gt;&lt;font face="arial"&gt;&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;span style="background-color: white; font-family: arial;"&gt;function. The type of the resulting array is deduced from the type of the elements in the sequences.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;span style="background-color: white; font-family: arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import numpy as np&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; a = np.array([1,2,3,4])&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;a&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;array([1,2,3,4])&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;a.dtype&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;dtype('int64')&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;b = np.array([1.2,2.4,3.6,7.8])&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;b&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;array([1.2,2.4,3.6,7.8])&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;b.dtype&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;dtype("float64")&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;span style="background-color: white; font-family: arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;span style="background-color: white; font-family: arial;"&gt;You can change the datatype of b array as int while declaring the b array.&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;span style="background-color: white; font-family: arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;span style="background-color: white; font-family: arial;"&gt;You can know the dimension of the array by using the shape attribute and also you can change the dimension by using the reshape method in NumPy.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;span style="background-color: white; font-family: arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;span style="background-color: white; font-family: arial;"&gt;When you want an array with all zeroes or all ones then you can use the method zeroes and ones.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;span style="background-color: white; font-family: arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; a = np.zeroes(4,dtype=float)&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; b = np.ones(5,dtype=int)&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;b&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;array([1,1,1,1,1])&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;a&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;array([0.,0.,0.,0.])&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; font-size: 14px; white-space: pre;"&gt;&lt;font face="courier"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white;"&gt;Creating an array, shaping, and reshaping the array and operations on the array like transpose of the array, concatenate and array mathematics.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white;"&gt;You can see a few examples in&amp;nbsp; the file:&amp;nbsp;&lt;a href="https://colab.research.google.com/drive/1ep1TUeNpxMg_53Rk0KQHbZcAvZq1fGes?usp=sharing" target="_blank"&gt;NumPy Quick tutorial&lt;/a&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="#333333" face="arial" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/6711098076220302257/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/NumPy-Quick-tutorial.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6711098076220302257" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6711098076220302257" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/NumPy-Quick-tutorial.html" rel="alternate" title="NumPy Quick tutorial - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-3026153761478576199</id><published>2020-06-25T23:13:00.002+05:30</published><updated>2020-06-25T23:13:46.962+05:30</updated><title type="text">How to plot the data by using pandas? - Letsprogram</title><content type="html">&lt;font color="black" size="4"&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If we have large data we cannot analyze each and every value so we calculate the average of the total data. To know how data is changing like increase or decrease we have to plot a graph to understand it and again you cannot plot the whole data. pandas provides plotting your data out of the box, using the power of Matplotlib. You can pick the plot type (scatter, bar, boxplot,…) corresponding to your data.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style="background-color: #fafafa; border: 1px solid rgb(201, 201, 201); box-shadow: rgb(216, 216, 216) 1px 1px 1px; box-sizing: border-box; color: #222222; font-size: 13.125px; line-height: 1.2em; margin-bottom: 1.5em; margin-top: 1.5em; overflow: auto hidden; padding: 10px;"&gt;&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;In [1]: &lt;/span&gt;&lt;span class="kn" style="box-sizing: border-box; color: #007020; font-weight: bold;"&gt;import&lt;/span&gt; &lt;span class="nn" style="box-sizing: border-box; color: #0e84b5; font-weight: bold;"&gt;pandas&lt;/span&gt; &lt;span class="k" style="box-sizing: border-box; color: #007020; font-weight: bold;"&gt;as&lt;/span&gt; &lt;span class="nn" style="box-sizing: border-box; color: #0e84b5; font-weight: bold;"&gt;pd&lt;/span&gt;
&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;In [2]: &lt;/span&gt;&lt;span class="kn" style="box-sizing: border-box; color: #007020; font-weight: bold;"&gt;import&lt;/span&gt; &lt;span class="nn" style="box-sizing: border-box; color: #0e84b5; font-weight: bold;"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k" style="box-sizing: border-box; color: #007020; font-weight: bold;"&gt;as&lt;/span&gt; &lt;span class="nn" style="box-sizing: border-box; color: #0e84b5; font-weight: bold;"&gt;plt&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="well"&gt;Data used for this tutorial :&lt;br /&gt;&lt;br /&gt;&lt;button data-target="#demo" data-toggle="collapse"&gt;Air Quality Data&lt;/button&gt;&lt;div class="collapse" id="demo"&gt;&lt;font face="arial" size="4"&gt;For this tutorial, air quality data about NO2 is used, made available by openaq, and using the py-openaq package. The air_quality_no2.csv data set provides NO2 values for the measurement stations FR04014, BETR801, and London Westminster in respectively Paris, Antwerp, and London. Download the data by clicking the button &lt;a class="btn btn-info" href="https://drive.google.com/file/d/1GL8hUHQDzszGutdcEGYEzhuPrhqlXwdf/view?usp=sharing" role="button"&gt;Link Button&lt;/a&gt;&lt;/font&gt; &lt;/div&gt;&lt;div class="collapse" id="demo"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;script src="https://gist.github.com/signatureratings/3724919b557ee44059bcc9d9eb50d0d7.js"&gt;&lt;/script&gt;
Now we have the data we should plot the data now.To have a quick visual check data&lt;/font&gt;&lt;br /&gt; &lt;div class="panel panel-default"&gt; &lt;div class="panel-heading"&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;air_quality.plot()&lt;br /&gt;&amp;lt;matplotlib.ax&lt;span style="font-family: arial;"&gt;es._subplots.AxesSubplot at 0x7fbbf7dced30&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div class="panel-heading"&gt;&lt;img alt="../../_images/04_airqual_quick.png" src="https://pandas.pydata.org/docs/_images/04_airqual_quick.png" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt; We now not used Matplotlib module by default pandas DataFrame will create a plot for each of the columns with the numeric data.&lt;/font&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;air_quality["station_paris"].plot()&lt;/b&gt;&lt;/font&gt;&lt;div&gt;&lt;b&gt;&lt;span style="background-color: white; color: #212121; font-size: 14px; white-space: pre;"&gt;&lt;font face="courier"&gt;&amp;lt;matplotlib.axe&lt;/font&gt;&lt;/span&gt;&lt;span style="color: #212121; font-size: 14px; white-space: pre;"&gt;&lt;font face="courier"&gt;s._subplots.AxesSubplot at 0x7&lt;/font&gt;&lt;/span&gt;&lt;span style="color: #212121; font-size: 14px; white-space: pre;"&gt;&lt;font face="courier"&gt;fbbf7dced30&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;img alt="../../_images/04_airqual_paris.png" src="https://pandas.pydata.org/docs/_images/04_airqual_paris.png" /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #212121; font-size: 14px; white-space: pre;"&gt;&lt;b&gt;&lt;font face="courier"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;font face="arial"&gt; Till now the plots are made by the pandas module. To do these basic plotting you can use pandas plot method.&lt;/font&gt;&lt;div&gt;&lt;font face="arial"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;ul class="task-bullet" style="background-color: white; box-sizing: border-box; color: #333333; font-family: Lato, sans-serif; font-size: 15px; list-style: none; margin-bottom: 1rem; margin-top: 2em; padding-left: 0px;"&gt;&lt;li style="border-left: 1px solid rgb(19, 6, 84); box-sizing: border-box; padding-left: 1em;"&gt;&lt;p style="box-sizing: border-box; font-size: 1.1rem; margin-bottom: 1.15rem; margin-top: 0px; padding-left: 0.75rem;"&gt;I want to visually compare the&amp;nbsp;&lt;span class="math notranslate nohighlight" style="box-sizing: border-box;"&gt;&lt;span class="MathJax_Preview" style="box-sizing: border-box; color: inherit;"&gt;&lt;/span&gt;&lt;span class="MathJax" data-mathml="&amp;lt;math xmlns=&amp;quot;http://www.w3.org/1998/Math/MathML&amp;quot;&amp;gt;&amp;lt;mi&amp;gt;N&amp;lt;/mi&amp;gt;&amp;lt;msub&amp;gt;&amp;lt;mn&amp;gt;0&amp;lt;/mn&amp;gt;&amp;lt;mn&amp;gt;2&amp;lt;/mn&amp;gt;&amp;lt;/msub&amp;gt;&amp;lt;/math&amp;gt;" id="MathJax-Element-3-Frame" role="presentation" style="border: 0px; box-sizing: border-box; direction: ltr; display: inline; float: none; font-size: 16.5px; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; overflow-wrap: normal; padding: 0px; position: relative; white-space: nowrap; word-spacing: normal;" tabindex="0"&gt;&lt;nobr aria-hidden="true" style="border: 0px; box-sizing: border-box; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none 0s ease 0s; vertical-align: 0px;"&gt;&lt;span class="math" id="MathJax-Span-13" style="border: 0px; box-sizing: content-box; display: inline-block; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: 0px; width: 2.178em;"&gt;&lt;span style="border: 0px; box-sizing: content-box; display: inline-block; font-size: 19.305px; height: 0px; line-height: normal; margin: 0px; padding: 0px; position: relative; transition: none 0s ease 0s; vertical-align: 0px; width: 1.867em;"&gt;&lt;span style="border: 0px; box-sizing: content-box; clip: rect(1.349em, 1001.87em, 2.489em, -999.997em); left: 0em; line-height: normal; margin: 0px; padding: 0px; position: absolute; top: -2.173em; transition: none 0s ease 0s; vertical-align: 0px;"&gt;&lt;span class="mrow" id="MathJax-Span-14" style="border: 0px; box-sizing: content-box; display: inline; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: 0px;"&gt;&lt;span class="mi" id="MathJax-Span-15" style="border: 0px; box-sizing: content-box; display: inline; font-family: MathJax_Math-italic; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: 0px;"&gt;N&lt;span style="border: 0px; box-sizing: content-box; display: inline-block; height: 1px; line-height: normal; margin: 0px; overflow: hidden; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: 0px; width: 0.106em;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="msubsup" id="MathJax-Span-16" style="border: 0px; box-sizing: content-box; display: inline; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: 0px;"&gt;&lt;span style="border: 0px; box-sizing: content-box; display: inline-block; height: 0px; line-height: normal; margin: 0px; padding: 0px; position: relative; transition: none 0s ease 0s; vertical-align: 0px; width: 0.935em;"&gt;&lt;span style="border: 0px; box-sizing: content-box; clip: rect(3.162em, 1000.47em, 4.147em, -999.997em); left: 0em; line-height: normal; margin: 0px; padding: 0px; position: absolute; top: -3.986em; transition: none 0s ease 0s; vertical-align: 0px;"&gt;&lt;span class="mn" id="MathJax-Span-17" style="border: 0px; box-sizing: content-box; display: inline; font-family: MathJax_Main; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: 0px;"&gt;0&lt;/span&gt;&lt;span style="border: 0px; box-sizing: content-box; display: inline-block; height: 3.991em; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: 0px; width: 0px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="border: 0px; box-sizing: content-box; left: 0.521em; line-height: normal; margin: 0px; padding: 0px; position: absolute; top: -3.831em; transition: none 0s ease 0s; vertical-align: 0px;"&gt;&lt;span class="mn" id="MathJax-Span-18" style="border: 0px; box-sizing: content-box; display: inline; font-family: MathJax_Main; font-size: 13.6486px; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: 0px;"&gt;2&lt;/span&gt;&lt;span style="border: 0px; box-sizing: content-box; display: inline-block; height: 3.991em; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: 0px; width: 0px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="border: 0px; box-sizing: content-box; display: inline-block; height: 2.178em; line-height: normal; margin: 0px; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: 0px; width: 0px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="border-bottom-style: initial; border-color: initial; border-image: initial; border-left-style: solid; border-right-style: initial; border-top-style: initial; border-width: 0px; box-sizing: content-box; display: inline-block; height: 1.094em; line-height: normal; margin: 0px; overflow: hidden; padding: 0px; position: static; transition: none 0s ease 0s; vertical-align: -0.239em; width: 0px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/nobr&gt;&lt;span class="MJX_Assistive_MathML" role="presentation" style="border: 0px; box-sizing: content-box; clip: rect(1px, 1px, 1px, 1px); display: inline; height: 1px !important; left: 0px; line-height: normal; margin: 0px; overflow: hidden !important; padding: 0px; position: static; top: 0px; transition: none 0s ease 0s; user-select: none; vertical-align: 0px; width: 1px !important;"&gt;&lt;math xmlns="http://www.w3.org/1998/Math/MathML"&gt;&lt;mi&gt;N&lt;/mi&gt;&lt;msub&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;values measured in London versus Paris.&lt;/p&gt;&lt;div class="highlight-ipython notranslate" style="box-sizing: border-box; clear: both; margin: 1em 0px;"&gt;&lt;div class="highlight" style="background: rgb(238, 255, 204); box-sizing: border-box; clear: both;"&gt;&lt;pre style="background-color: #fafafa; border: 1px solid rgb(201, 201, 201); box-shadow: rgb(216, 216, 216) 1px 1px 1px; box-sizing: border-box; clear: both; color: #222222; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; line-height: 1.2em; margin-bottom: 0px; margin-top: 0px; overflow: auto hidden; padding: 10px;"&gt;&lt;span style="box-sizing: border-box;"&gt;&lt;/span&gt;&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;In [7]: &lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;air_quality&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;plot&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;scatter&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;x&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt;&lt;span class="s2" style="box-sizing: border-box; color: #4070a0;"&gt;"station_london"&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;,&lt;/span&gt;
&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;   ...: &lt;/span&gt;                         &lt;span class="n" style="box-sizing: border-box;"&gt;y&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt;&lt;span class="s2" style="box-sizing: border-box; color: #4070a0;"&gt;"station_paris"&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;,&lt;/span&gt;
&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;   ...: &lt;/span&gt;                         &lt;span class="n" style="box-sizing: border-box;"&gt;alpha&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt;&lt;span class="mf" style="box-sizing: border-box; color: #208050;"&gt;0.5&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;)&lt;/span&gt;
&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;   ...: &lt;/span&gt;
&lt;span class="gh" style="box-sizing: border-box; color: navy; font-weight: bold;"&gt;Out[7]: &lt;/span&gt;&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt;&amp;lt;matplotlib.axes._subplots.AxesSubplot at 0x7f534481f710&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;img alt="../../_images/04_airqual_scatter.png" src="https://pandas.pydata.org/docs/_images/04_airqual_scatter.png" style="border: 0px; box-sizing: border-box; margin-bottom: 0px; max-width: 100%; vertical-align: middle;" /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style="background-color: white; box-sizing: border-box; color: #333333; margin-bottom: 1.15rem; margin-top: 0px;"&gt;&lt;font face="arial"&gt;Apart from the default&amp;nbsp;&lt;code class="docutils literal notranslate" style="box-sizing: border-box; color: #e83e8c; overflow-wrap: break-word;"&gt;&lt;span class="pre" style="box-sizing: border-box; hyphens: none;"&gt;line&lt;/span&gt;&lt;/code&gt;&amp;nbsp;the plot when using the&amp;nbsp;&lt;code class="docutils literal notranslate" style="box-sizing: border-box; color: #e83e8c; overflow-wrap: break-word;"&gt;&lt;span class="pre" style="box-sizing: border-box; hyphens: none;"&gt;plot&lt;/span&gt;&lt;/code&gt;&amp;nbsp;function, a number of alternatives are available to plot data. Let’s use some standard Python to get an overview of the available plot methods:&lt;/font&gt;&lt;/p&gt;&lt;div class="highlight-ipython notranslate" style="background-color: white; box-sizing: border-box; clear: both; color: #333333; font-family: Lato, sans-serif; font-size: 16px; margin: 1em 0px;"&gt;&lt;div class="highlight" style="background: rgb(238, 255, 204); box-sizing: border-box; clear: both;"&gt;&lt;pre style="background-color: #fafafa; border: 1px solid rgb(201, 201, 201); box-shadow: rgb(216, 216, 216) 1px 1px 1px; box-sizing: border-box; clear: both; color: #222222; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14.125px; line-height: 1.2em; margin-bottom: 0px; margin-top: 0px; overflow: auto hidden; padding: 10px;"&gt;&lt;span style="box-sizing: border-box;"&gt;&lt;/span&gt;&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;In [8]: &lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;[&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;method_name&lt;/span&gt; &lt;span class="k" style="box-sizing: border-box; color: #007020; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span class="n" style="box-sizing: border-box;"&gt;method_name&lt;/span&gt; &lt;span class="ow" style="box-sizing: border-box; color: #007020; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span class="nb" style="box-sizing: border-box; color: #007020;"&gt;dir&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;air_quality&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;plot&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;)&lt;/span&gt;
&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;   ...: &lt;/span&gt;    &lt;span class="k" style="box-sizing: border-box; color: #007020; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span class="ow" style="box-sizing: border-box; color: #007020; font-weight: bold;"&gt;not&lt;/span&gt; &lt;span class="n" style="box-sizing: border-box;"&gt;method_name&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;startswith&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="s2" style="box-sizing: border-box; color: #4070a0;"&gt;"_"&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;)]&lt;/span&gt;
&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;   ...: &lt;/span&gt;
&lt;span class="gh" style="box-sizing: border-box; color: navy; font-weight: bold;"&gt;Out[8]: &lt;/span&gt;&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt;&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt;['area',&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 'bar',&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 'barh',&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 'box',&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 'density',&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 'hexbin',&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 'hist',&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 'kde',&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 'line',&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 'pie',&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 'scatter']&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="admonition note" style="background-color: white; border-bottom-color: rgb(0, 123, 255); border-left: 0.2rem solid rgb(0, 123, 255); border-radius: 0.1rem; border-right-color: rgb(0, 123, 255); border-top-color: rgb(0, 123, 255); box-shadow: rgba(0, 0, 0, 0.05) 0px 0.2rem 0.5rem, rgba(0, 0, 0, 0.1) 0px 0px 0.05rem; box-sizing: border-box; break-inside: avoid; clear: both; color: #333333; font-family: Lato, sans-serif; font-size: 15px; margin-bottom: 10px; margin-left: 0px !important; margin-right: 0px !important; margin-top: 10px; overflow: auto hidden; padding: 7px; transition: color 0.25s ease 0s, background-color 0.25s ease 0s, border-color 0.25s ease 0s;"&gt;&lt;p class="admonition-title" style="background-color: #e7f2fa; box-sizing: border-box; font-size: 1em; font-weight: 700; margin: 0px -0.6rem !important; padding: 0.4rem 0.6rem 0.4rem 2rem; position: relative;"&gt;Note&lt;/p&gt;&lt;p style="box-sizing: border-box; font-size: 1em; margin-bottom: 0px; margin-top: 0.4em;"&gt;In many development environments as well as ipython and jupyter notebook, use the TAB button to get an overview of the available methods, for example&amp;nbsp;&lt;code class="docutils literal notranslate" style="box-sizing: border-box; color: #e83e8c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; overflow-wrap: break-word;"&gt;&lt;span class="pre" style="box-sizing: border-box; hyphens: none;"&gt;air_quality.plot.&lt;/span&gt;&lt;/code&gt;&amp;nbsp;+ TAB.&lt;/p&gt;&lt;/div&gt;&lt;p style="background-color: white; box-sizing: border-box; color: #333333; font-family: Lato, sans-serif; font-size: 15px; margin-bottom: 1.15rem; margin-top: 0px;"&gt;One of the options is&amp;nbsp;&lt;a class="reference internal" href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.box.html#pandas.DataFrame.plot.box" style="background-color: transparent; box-sizing: border-box; color: #005b81; text-decoration-line: none;" title="pandas.DataFrame.plot.box"&gt;&lt;code class="xref py py-meth docutils literal notranslate" style="background-color: transparent; box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; overflow-wrap: break-word;"&gt;&lt;span class="pre" style="box-sizing: border-box; hyphens: none;"&gt;DataFrame.plot.box()&lt;/span&gt;&lt;/code&gt;&lt;/a&gt;, which refers to a&amp;nbsp;&lt;a class="reference external" href="https://en.wikipedia.org/wiki/Box_plot" style="background-color: transparent; box-sizing: border-box; color: #005b81; text-decoration-line: none;"&gt;boxplot&lt;/a&gt;. The&amp;nbsp;&lt;code class="docutils literal notranslate" style="box-sizing: border-box; color: #e83e8c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; overflow-wrap: break-word;"&gt;&lt;span class="pre" style="box-sizing: border-box; hyphens: none;"&gt;box&lt;/span&gt;&lt;/code&gt;&amp;nbsp;method is applicable on the air quality example data:&lt;/p&gt;&lt;div class="highlight-ipython notranslate" style="background-color: white; box-sizing: border-box; clear: both; color: #333333; font-family: Lato, sans-serif; font-size: 15px; margin: 1em 0px;"&gt;&lt;div class="highlight" style="background: rgb(238, 255, 204); box-sizing: border-box; clear: both;"&gt;&lt;pre style="background-color: #fafafa; border: 1px solid rgb(201, 201, 201); box-shadow: rgb(216, 216, 216) 1px 1px 1px; box-sizing: border-box; clear: both; color: #222222; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; line-height: 1.2em; margin-bottom: 0px; margin-top: 0px; overflow: auto hidden; padding: 10px;"&gt;&lt;span style="box-sizing: border-box;"&gt;&lt;/span&gt;&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;In [9]: &lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;air_quality&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;plot&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;box&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;()&lt;/span&gt;
&lt;span class="gh" style="box-sizing: border-box; color: navy; font-weight: bold;"&gt;Out[9]: &lt;/span&gt;&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt;&amp;lt;matplotlib.axes._subplots.AxesSubplot at 0x7f5344381810&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;img alt="../../_images/04_airqual_boxplot.png" src="https://pandas.pydata.org/docs/_images/04_airqual_boxplot.png" style="background-color: white; border: 0px; box-sizing: border-box; color: #333333; font-family: Lato, sans-serif; font-size: 15px; max-width: 100%; vertical-align: middle;" /&gt;&lt;span style="background-color: white; color: #333333; font-family: Lato, sans-serif; font-size: 15px;"&gt;&lt;/span&gt;&lt;div class="d-flex flex-row gs-torefguide" style="align-items: center; background-color: white; box-sizing: border-box; color: #333333; display: flex !important; flex-direction: row !important; font-family: Lato, sans-serif; font-size: 0.9rem;"&gt;&lt;span class="badge badge-info" style="background-color: #130654; border-radius: 0.25rem; box-sizing: border-box; color: white; display: inline-block; font-size: 10.125px; font-weight: 700; line-height: 1; margin: 10px 10px 10px 0px; padding: 5px; text-align: center; transition: color 0.15s ease-in-out 0s, background-color 0.15s ease-in-out 0s, border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s; vertical-align: baseline; white-space: nowrap;"&gt;To user guide&lt;/span&gt;&lt;p style="box-sizing: border-box; font-size: 1em; margin-bottom: 1.15rem; margin-top: 1rem;"&gt;For an introduction to plots other than the default line plot, see the user guide section about&amp;nbsp;&lt;a class="reference internal" href="https://pandas.pydata.org/docs/user_guide/visualization.html#visualization-other" style="background-color: transparent; border-bottom: 1px solid rgba(255, 202, 0, 0.953); box-shadow: rgba(255, 202, 0, 0.953) 0px -10px 0px inset; box-sizing: border-box; color: #130654; margin-left: 5px; text-decoration-line: none;"&gt;&lt;span class="std std-ref" style="box-sizing: border-box;"&gt;supported plot styles&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;ul class="task-bullet" style="background-color: white; box-sizing: border-box; color: #333333; font-family: Lato, sans-serif; font-size: 15px; list-style: none; margin-bottom: 1rem; margin-top: 2em; padding-left: 0px;"&gt;&lt;li style="border-left: 1px solid rgb(19, 6, 84); box-sizing: border-box; padding-left: 1em;"&gt;&lt;p style="box-sizing: border-box; font-size: 1.1rem; margin-bottom: 1.15rem; margin-top: 0px; padding-left: 0.75rem;"&gt;I want each of the columns in a separate subplot.&lt;/p&gt;&lt;div class="highlight-ipython notranslate" style="box-sizing: border-box; clear: both; margin: 1em 0px;"&gt;&lt;div class="highlight" style="background: rgb(238, 255, 204); box-sizing: border-box; clear: both;"&gt;&lt;pre style="background-color: #fafafa; border: 1px solid rgb(201, 201, 201); box-shadow: rgb(216, 216, 216) 1px 1px 1px; box-sizing: border-box; clear: both; color: #222222; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; line-height: 1.2em; margin-bottom: 0px; margin-top: 0px; overflow: auto hidden; padding: 10px;"&gt;&lt;span style="box-sizing: border-box;"&gt;&lt;/span&gt;&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;In [10]: &lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;axs&lt;/span&gt; &lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt; &lt;span class="n" style="box-sizing: border-box;"&gt;air_quality&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;plot&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;area&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;figsize&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="mi" style="box-sizing: border-box; color: #208050;"&gt;12&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;,&lt;/span&gt; &lt;span class="mi" style="box-sizing: border-box; color: #208050;"&gt;4&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;),&lt;/span&gt; &lt;span class="n" style="box-sizing: border-box;"&gt;subplots&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt;&lt;span class="kc" style="box-sizing: border-box; color: #007020; font-weight: bold;"&gt;True&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;img alt="../../_images/04_airqual_area_subplot.png" src="https://pandas.pydata.org/docs/_images/04_airqual_area_subplot.png" style="border: 0px; box-sizing: border-box; max-width: 100%; vertical-align: middle;" /&gt;&lt;p style="box-sizing: border-box; font-size: 1em; margin-bottom: 0px; margin-top: 0px;"&gt;Separate subplots for each of the data columns is supported by the&amp;nbsp;&lt;code class="docutils literal notranslate" style="box-sizing: border-box; color: #e83e8c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; overflow-wrap: break-word;"&gt;&lt;span class="pre" style="box-sizing: border-box; hyphens: none;"&gt;subplots&lt;/span&gt;&lt;/code&gt;&amp;nbsp;argument of the&amp;nbsp;&lt;code class="docutils literal notranslate" style="box-sizing: border-box; color: #e83e8c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; overflow-wrap: break-word;"&gt;&lt;span class="pre" style="box-sizing: border-box; hyphens: none;"&gt;plot&lt;/span&gt;&lt;/code&gt;&amp;nbsp;functions. The builtin options available in each of the pandas plot functions that are worthwhile to have a look.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="d-flex flex-row gs-torefguide" style="align-items: center; background-color: white; box-sizing: border-box; color: #333333; display: flex !important; flex-direction: row !important; font-family: Lato, sans-serif; font-size: 0.9rem;"&gt;&lt;span class="badge badge-info" style="background-color: #130654; border-radius: 0.25rem; box-sizing: border-box; color: white; display: inline-block; font-size: 10.125px; font-weight: 700; line-height: 1; margin: 10px 10px 10px 0px; padding: 5px; text-align: center; transition: color 0.15s ease-in-out 0s, background-color 0.15s ease-in-out 0s, border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s; vertical-align: baseline; white-space: nowrap;"&gt;To user guide&lt;/span&gt;&lt;p style="box-sizing: border-box; font-size: 1em; margin-bottom: 1.15rem; margin-top: 1rem;"&gt;Some more formatting options are explained in the user guide section on&amp;nbsp;&lt;a class="reference internal" href="https://pandas.pydata.org/docs/user_guide/visualization.html#visualization-formatting" style="background-color: transparent; border-bottom: 1px solid rgba(255, 202, 0, 0.953); box-shadow: rgba(255, 202, 0, 0.953) 0px -10px 0px inset; box-sizing: border-box; color: #130654; margin-left: 5px; text-decoration-line: none;"&gt;&lt;span class="std std-ref" style="box-sizing: border-box;"&gt;plot formatting&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;ul class="task-bullet" style="background-color: white; box-sizing: border-box; color: #333333; font-family: Lato, sans-serif; font-size: 15px; list-style: none; margin-bottom: 1rem; margin-top: 2em; padding-left: 0px;"&gt;&lt;li style="border-left: 1px solid rgb(19, 6, 84); box-sizing: border-box; padding-left: 1em;"&gt;&lt;p style="box-sizing: border-box; font-size: 1.1rem; margin-bottom: 1.15rem; margin-top: 0px; padding-left: 0.75rem;"&gt;I want to further customize, extend or save the resulting plot.&lt;/p&gt;&lt;div class="highlight-ipython notranslate" style="box-sizing: border-box; clear: both; margin: 1em 0px;"&gt;&lt;div class="highlight" style="background: rgb(238, 255, 204); box-sizing: border-box; clear: both;"&gt;&lt;pre style="background-color: #fafafa; border: 1px solid rgb(201, 201, 201); box-shadow: rgb(216, 216, 216) 1px 1px 1px; box-sizing: border-box; clear: both; color: #222222; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; line-height: 1.2em; margin-bottom: 0px; margin-top: 0px; overflow: auto hidden; padding: 10px;"&gt;&lt;span style="box-sizing: border-box;"&gt;&lt;/span&gt;&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;In [11]: &lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;fig&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;,&lt;/span&gt; &lt;span class="n" style="box-sizing: border-box;"&gt;axs&lt;/span&gt; &lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt; &lt;span class="n" style="box-sizing: border-box;"&gt;plt&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;subplots&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;figsize&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="mi" style="box-sizing: border-box; color: #208050;"&gt;12&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;,&lt;/span&gt; &lt;span class="mi" style="box-sizing: border-box; color: #208050;"&gt;4&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;));&lt;/span&gt;

&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;In [12]: &lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;air_quality&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;plot&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;area&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;ax&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;axs&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;);&lt;/span&gt;

&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;In [13]: &lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;axs&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;set_ylabel&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="s2" style="box-sizing: border-box; color: #4070a0;"&gt;"NO$_2$ concentration"&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;);&lt;/span&gt;

&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-weight: bold;"&gt;In [14]: &lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;fig&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;savefig&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="s2" style="box-sizing: border-box; color: #4070a0;"&gt;"no2_concentrations.png"&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;img alt="../../_images/04_airqual_customized.png" src="https://pandas.pydata.org/docs/_images/04_airqual_customized.png" style="border: 0px; box-sizing: border-box; margin-bottom: 0px; max-width: 100%; vertical-align: middle;" /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style="background-color: white; box-sizing: border-box; color: #333333; font-family: Lato, sans-serif; font-size: 15px; margin-bottom: 1.15rem; margin-top: 0px;"&gt;Each of the plot objects created by pandas are a&amp;nbsp;&lt;a class="reference external" href="https://matplotlib.org/" style="background-color: transparent; box-sizing: border-box; color: #005b81; text-decoration-line: none;"&gt;matplotlib&lt;/a&gt;&amp;nbsp;object. As Matplotlib provides plenty of options to customize plots, making the link between pandas and Matplotlib explicit enables all the power of matplotlib to the plot. This strategy is applied in the previous example:&lt;/p&gt;&lt;div class="highlight-default notranslate" style="background-color: white; box-sizing: border-box; clear: both; color: #333333; font-family: Lato, sans-serif; font-size: 15px; margin: 1em 0px;"&gt;&lt;div class="highlight" style="background: rgb(238, 255, 204); box-sizing: border-box; clear: both;"&gt;&lt;pre style="background-color: #fafafa; border: 1px solid rgb(201, 201, 201); box-shadow: rgb(216, 216, 216) 1px 1px 1px; box-sizing: border-box; clear: both; color: #222222; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; line-height: 1.2em; margin-bottom: 0px; margin-top: 0px; overflow: auto hidden; padding: 10px;"&gt;&lt;span style="box-sizing: border-box;"&gt;&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;fig&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;,&lt;/span&gt; &lt;span class="n" style="box-sizing: border-box;"&gt;axs&lt;/span&gt; &lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt; &lt;span class="n" style="box-sizing: border-box;"&gt;plt&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;subplots&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;figsize&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="mi" style="box-sizing: border-box; color: #208050;"&gt;12&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;,&lt;/span&gt; &lt;span class="mi" style="box-sizing: border-box; color: #208050;"&gt;4&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;))&lt;/span&gt;        &lt;span class="c1" style="box-sizing: border-box; color: #408090; font-style: italic;"&gt;# Create an empty matplotlib Figure and Axes&lt;/span&gt;
&lt;span class="n" style="box-sizing: border-box;"&gt;air_quality&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;plot&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;area&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;ax&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;=&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;axs&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;)&lt;/span&gt;                   &lt;span class="c1" style="box-sizing: border-box; color: #408090; font-style: italic;"&gt;# Use pandas to put the area plot on the prepared Figure/Axes&lt;/span&gt;
&lt;span class="n" style="box-sizing: border-box;"&gt;axs&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;set_ylabel&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="s2" style="box-sizing: border-box; color: #4070a0;"&gt;"NO$_2$ concentration"&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;)&lt;/span&gt;          &lt;span class="c1" style="box-sizing: border-box; color: #408090; font-style: italic;"&gt;# Do any matplotlib customization you like&lt;/span&gt;
&lt;span class="n" style="box-sizing: border-box;"&gt;fig&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box;"&gt;savefig&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;(&lt;/span&gt;&lt;span class="s2" style="box-sizing: border-box; color: #4070a0;"&gt;"no2_concentrations.png"&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box;"&gt;)&lt;/span&gt;           &lt;span class="c1" style="box-sizing: border-box; color: #408090; font-style: italic;"&gt;# Save the Figure/Axes using the existing matplotlib method.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="shadow gs-callout gs-callout-remember" style="align-items: center; background-color: white; border-color: rgb(238, 238, 238) rgb(238, 238, 238) rgb(238, 238, 238) rgb(240, 173, 78); border-image: initial; border-radius: 3px; border-style: solid; border-width: 1px 1px 1px 5px; box-shadow: rgba(0, 0, 0, 0.15) 0px 0.5rem 1rem !important; box-sizing: border-box; color: #333333; font-family: Lato, sans-serif; font-size: 1.2rem; margin: 20px 0px; padding: 20px;"&gt;&lt;h4 style="box-sizing: border-box; color: #f0ad4e; font-family: &amp;quot;Open Sans&amp;quot;, sans-serif; font-size: 1.44em; font-weight: 400; line-height: 1.15; margin: 0px 0px 5px;"&gt;REMEMBER&lt;/h4&gt;&lt;ul class="simple" style="box-sizing: border-box; margin-bottom: 1rem; margin-top: 0px;"&gt;&lt;li style="box-sizing: border-box;"&gt;&lt;p style="box-sizing: border-box; font-size: 1em; margin-bottom: 0px; margin-top: 0px;"&gt;The&amp;nbsp;&lt;code class="docutils literal notranslate" style="border-radius: 3px; box-sizing: border-box; color: #e83e8c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 15.75px; overflow-wrap: break-word;"&gt;&lt;span class="pre" style="box-sizing: border-box; hyphens: none;"&gt;.plot.*&lt;/span&gt;&lt;/code&gt;&amp;nbsp;methods are applicable on both Series and DataFrames&lt;/p&gt;&lt;/li&gt;&lt;li style="box-sizing: border-box;"&gt;&lt;p style="box-sizing: border-box; font-size: 1em; margin-bottom: 0px; margin-top: 0px;"&gt;By default, each of the columns is plotted as a different element (line, boxplot,…)&lt;/p&gt;&lt;/li&gt;&lt;li style="box-sizing: border-box;"&gt;&lt;p style="box-sizing: border-box; font-size: 1em; margin-bottom: 0px; margin-top: 0px;"&gt;Any plot created by pandas is a Matplotlib object.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/3026153761478576199/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/how-to-plot-data-by-using-pandas.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/3026153761478576199" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/3026153761478576199" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/how-to-plot-data-by-using-pandas.html" rel="alternate" title="How to plot the data by using pandas? - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-8826502485353713073</id><published>2020-06-14T11:00:00.001+05:30</published><updated>2020-06-14T11:00:42.341+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="pandas"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Getting started with Pandas - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;br /&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Before you use pandas install it in your PC depending on your environment you are working. If you are using &lt;a href="http://docs.continuum.io/anaconda/" target="_blank"&gt;anaconda&lt;/a&gt; or miniconda use &lt;/font&gt;&lt;font face="courier" size="4"&gt;conda install pandas&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;in the respective interpreter. If you use normal python IDE the download and install pandas using pip by the command pip install pandas. If you had any difficulties in installing the pandas check this link: &lt;a href="https://pandas.pydata.org/docs/getting_started/install.html#install" target="_blank"&gt;installing pandas&lt;/a&gt;.&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;After installing it in your PC import the pandas package into your program or interpreter.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import pandas as pd&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;pd is just an alias for pandas instead of typing the whole name and it is assumed as a standard practice.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;pandas &lt;/b&gt;is a fast, powerful, flexible, and easy to use open-source data analysis and manipulation tool, built on top of the Python programming language.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;we now know that pandas is a data manipulation tool but the question is&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;what kind of data do pandas handle?&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When working with tabular data, such as data stored in spreadsheets or databases, Pandas is the right tool for you. Pandas will help you to explore, clean, and process your data. In Pandas, a data table is called a &lt;b&gt;DataFrame&lt;/b&gt;.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;Pandas DataFrame Representation&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW0ABX6Ksrz22aI4lX1r6qjbpJ3aHIx_uOXio3kFyTnOi_UM_5vy5aLw0Vma9c8rRqX-k-Ko09JXQ-mb_jMicFAGR1zIzxRN5yRntHoAxo73zQNEghnmcBeCBlMdDUxlFAzv7L5KmHgKc/s1350/pandas_df.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Pandas DataFrame - Letsprogram" border="0" data-original-height="629" data-original-width="1350" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW0ABX6Ksrz22aI4lX1r6qjbpJ3aHIx_uOXio3kFyTnOi_UM_5vy5aLw0Vma9c8rRqX-k-Ko09JXQ-mb_jMicFAGR1zIzxRN5yRntHoAxo73zQNEghnmcBeCBlMdDUxlFAzv7L5KmHgKc/w640-h298/pandas_df.png" title="Pandas DataFrame - Letsprogram" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;I want to store the data of some movies I know the name of the movie, year released, and director.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/a03a2f3712b385a2b2bf2de307946a44.js"&gt;&lt;/script&gt;&lt;font face="arial" size="4"&gt;When using the Python dictionary here keys will be used as columns and values will be used as rows of the data frame.&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When selecting the single column from the pandas DataFrame the result will be Series. The selecting of a single column from the python dictionary is the same as the pandas DataFrame here.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;You can create a single column or Series from first.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;ages=pd.Series([19,16,32,29],name="age")&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;ages&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;0&amp;nbsp; &amp;nbsp;19&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;1&amp;nbsp; &amp;nbsp;16&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;2&amp;nbsp; &amp;nbsp; 32&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;3&amp;nbsp; &amp;nbsp; 29&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;Name: age,&amp;nbsp; dtype: int64&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;We stored the movie's information in df to get the lasted movie from all the collection of movies in the data we need to do something on the DataFrame.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&lt;font size="4"&gt;&amp;gt;&amp;gt;&amp;gt;df["year"].max(&amp;nbsp;&lt;/font&gt;&lt;span style="font-size: large;"&gt;)&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="courier"&gt;&lt;b&gt;2008&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;The latest movie was released in the year 2008. Not only max pandas will also provide you many functionalities.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;If you need basic statistics of a numerical table in the DataFrame use describe( ) method. df.describe( )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="admonition note" style="background-color: white; border-color: rgb(0, 123, 255); border-left-style: solid; border-left-width: 0.2rem; border-radius: 0.1rem; box-shadow: rgba(0, 0, 0, 0.05) 0px 0.2rem 0.5rem, rgba(0, 0, 0, 0.1) 0px 0px 0.05rem; box-sizing: border-box; break-inside: avoid; color: #333333; font-family: lato, sans-serif; font-size: 15px; margin: 10px 0px; overflow: hidden; padding: 7px; transition: all 0.25s ease 0s, all 0.25s ease 0s, all 0.25s ease 0s;"&gt;&lt;p class="admonition-title" style="background-color: #e7f2fa; box-sizing: border-box; font-size: 1em; font-weight: 700; margin: 0px -0.6rem; padding: 0.4rem 0.6rem 0.4rem 2rem; position: relative;"&gt;Note&lt;/p&gt;&lt;p style="box-sizing: border-box; font-size: 1em; margin-bottom: 0.4em; margin-top: 0.4em;"&gt;This is just a starting point. Similar to spreadsheet software, pandas represent data as a table with columns and rows. Apart from the representation, also the data manipulations and calculations you would do in spreadsheet software are supported by pandas. Continue reading the next tutorials to get started!&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;How to read and write data&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;I had a CSV file with data I had to read it to pandas DataFrame.&amp;nbsp; pandas gave &lt;/font&gt;&lt;font face="courier" size="4"&gt;read_csv( ) &lt;/font&gt;&lt;font face="arial" size="4"&gt;method to the operations on the file. pandas also support the other file formats like SQL, Excel, JSON, etc. each have a method with the prefix&lt;/font&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;read_*( )&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/340f2f3886e18cee71821a3850e6f99c.js"&gt;&lt;/script&gt;&lt;font face="arial" size="4"&gt; If you want to read first n columns use the &lt;/font&gt;&lt;font face="courier" size="4"&gt;head( )&lt;/font&gt;&lt;font face="arial" size="4"&gt; method or to read last n columns use &lt;/font&gt;&lt;font face="courier" size="4"&gt;tail( )&lt;/font&gt;&lt;font face="arial" size="4"&gt; method. The code written in the above program requires a titanic.csv file. Download the &lt;a href="http://raboninco.com/y0yQ" target="_blank"&gt;titanic.csv&lt;/a&gt; file.&lt;/font&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;You can get the datatypes details of all Series in the DataFrame by the &lt;i&gt;attribute&lt;/i&gt; dtypes in the pandas.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;You read the data from a CSV file to pandas DataFrames now you have to extract the data as your useful format. While &lt;/font&gt;&lt;font face="courier" size="4"&gt;read_*( )&lt;/font&gt;&lt;font face="arial" size="4"&gt; methods read the data&lt;/font&gt;&lt;font face="courier" size="4"&gt; to_*( ) &lt;/font&gt;&lt;font face="arial" size="4"&gt;extract the data from the pandas. To know more about the reading and writing methods check this link: &lt;a href="http://raboninco.com/y22R" target="_blank"&gt;pandas_methods&lt;/a&gt;.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&amp;gt;&amp;gt;&amp;gt;titanic.to_excel('titianic.xlsv', sheet_name="passengers")&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/font&gt;&lt;span class="gp" style="box-sizing: border-box; color: #c65d09; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; font-weight: bold;"&gt; &lt;/span&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;span class="n" style="box-sizing: border-box; color: #222222;"&gt;titanic&lt;/span&gt;&lt;span class="o" style="box-sizing: border-box; color: #666666;"&gt;.&lt;/span&gt;&lt;span class="n" style="box-sizing: border-box; color: #222222;"&gt;info&lt;/span&gt;&lt;span class="p" style="box-sizing: border-box; color: #222222;"&gt;()&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;pre style="background-color: #fafafa; border: 1px solid rgb(201, 201, 201); box-shadow: rgb(216, 216, 216) 1px 1px 1px; box-sizing: border-box; color: #222222; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13.125px; line-height: 1.2em; margin-bottom: 1.5em; margin-top: 1.5em; overflow: auto hidden; padding: 10px;"&gt;&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt;&amp;lt;class 'pandas.core.frame.DataFrame'&amp;gt;&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt;RangeIndex: 891 entries, 0 to 890&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt;Data columns (total 12 columns):&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; #   Column       Non-Null Count  Dtype  &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt;---  ------       --------------  -----  &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 0   PassengerId  891 non-null    int64  &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 1   Survived     891 non-null    int64  &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 2   Pclass       891 non-null    int64  &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 3   Name         891 non-null    object &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 4   Sex          891 non-null    object &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 5   Age          714 non-null    float64&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 6   SibSp        891 non-null    int64  &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 7   Parch        891 non-null    int64  &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 8   Ticket       891 non-null    object &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 9   Fare         891 non-null    float64&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 10  Cabin        204 non-null    object &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt; 11  Embarked     889 non-null    object &lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt;dtypes: float64(2), int64(5), object(5)&lt;/span&gt;
&lt;span class="go" style="box-sizing: border-box; color: #333333;"&gt;memory usage: 83.7+ KB&lt;/span&gt;&lt;/pre&gt;&lt;font face="arial" size="4"&gt;
If you want to know more than datatypes then we use info( ) method on the DataFrame. It provides you index value, Exact RAM used to hold the DataFrame as well. We can know the missing value numbers in the File. The info method is used to know the technical information about the data.&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;
&lt;div style="font-family: verdana; font-size: 10px; text-align: center; width: 728px;"&gt;&lt;a href="https://join-adf.ly/21768621"&gt;&lt;img border="0" height="90" src="https://cdn.adf.ly/images/banners/adfly.728x90.1.gif" title="AdF.ly - shorten links and earn money!" width="728" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="https://join-adf.ly/21768621"&gt;Get paid to share your links!&lt;/a&gt;&lt;/div&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/8826502485353713073/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/Getting-stared-with-pandas.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/8826502485353713073" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/8826502485353713073" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/Getting-stared-with-pandas.html" rel="alternate" title="Getting started with Pandas - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW0ABX6Ksrz22aI4lX1r6qjbpJ3aHIx_uOXio3kFyTnOi_UM_5vy5aLw0Vma9c8rRqX-k-Ko09JXQ-mb_jMicFAGR1zIzxRN5yRntHoAxo73zQNEghnmcBeCBlMdDUxlFAzv7L5KmHgKc/s72-w640-h298-c/pandas_df.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-3888551539557042444</id><published>2020-06-11T11:44:00.002+05:30</published><updated>2020-07-08T11:56:49.995+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="modules"/><title type="text">Modules in Python - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;font face="arial" size="4"&gt;We use functions to decrease the number of lines in the program and of course reusability. But any functions can be used in the same program but not outside. If you quit your interpreter the definitions you made are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead.  This is known as creating a &lt;b&gt;script&lt;/b&gt;.&lt;/font&gt;&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0UEBwLFq_lBPgMQJnKT4LGTsN0W1iflAtsPSHG8lUwkW97Est6b7pF28ecdS_wxOjDqQFa3YhntDFeiwRkTHh9NqIsJvTYyDzNilVc4_s3goclTdW1INA97lkl_bKqkAuTuEYrj67nIc/s6016/chris-ried-ieic5Tq8YMk-unsplash.jpg" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="4016" data-original-width="6016" height="428" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0UEBwLFq_lBPgMQJnKT4LGTsN0W1iflAtsPSHG8lUwkW97Est6b7pF28ecdS_wxOjDqQFa3YhntDFeiwRkTHh9NqIsJvTYyDzNilVc4_s3goclTdW1INA97lkl_bKqkAuTuEYrj67nIc/w640-h428/chris-ried-ieic5Tq8YMk-unsplash.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;font color=""&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Generally, developers handling with larger programs will split into multiple files for easy use. And also to use a function in another file instead of copying several times into each program we use scripting.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Python support this it has a way to put functions or definitions in an interactive instance of an interpreter called a module. We all know we import some modules into our programs by importing that module means we are importing some definitions which make our work fast and easier. Python has many modules.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The module is just a normal python file like any other with ends with .py extension. modules name is available for the value of global variable &lt;/font&gt;&lt;font face="courier" size="4"&gt;__name__.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import pandas as p&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;p.__name__&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;'pandas'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Create a file named prime.py in the current directory you are working and enter the following codes.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/1632f9a6d8aed284798e87d68fef441c.js"&gt;&lt;/script&gt;&lt;font face="arial" size="4"&gt;Now enter the Python interpreter and import this module with the following command:
&lt;/font&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import prime.py&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Now you had imported the definitions written in the prime.py file into your program without using the function names.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;prime.PRIME(3)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;'prime'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;prime.evenodd(2)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;'even'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;prime.__name__&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;'prime'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If you use any function many times in your program you can change the name by&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;even = prime.evenodd&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;even(3)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;'odd'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only the &lt;em&gt;first&lt;/em&gt; time the module name is encountered in an import statement. (They are also run if the file is executed as a script.)&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;font size="4"&gt;&lt;font face="arial"&gt;Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the module. Thus, the author of a module can use global variables in the module without worrying about accidental clashes with a user’s global variables. On the other hand, if you know what you are doing you can touch a module’s global variables with the same notation used to refer to its functions, &lt;/font&gt;&lt;font face="courier"&gt;&lt;code class="docutils literal notranslate"&gt;modname.itemname&lt;/code&gt;.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;Modules can import other modules.  It is customary but not required to place all &lt;code class="xref std std-keyword docutils literal notranslate"&gt;import&lt;/code&gt; statements at the beginning of a module (or script, for that matter).  The imported module names are placed in the importing module’s global symbol table.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;There is an another way to import all the definitions from the module.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;from pandas import *&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;This imports all the names except those starting with _. In most cases, programmers don't use those functions.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;Note that in general the practice of importing &lt;code class="docutils literal notranslate"&gt;*&lt;/code&gt; from a module or package is frowned upon since it often causes poorly readable code. However, it is okay to use it to save typing in interactive sessions.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;Sometimes we do not require every definition in the module if we imported very large modules which means your program has many statements to run which may decrease your program efficiency. so, to avoid that there is another way to import a&amp;nbsp; module.&lt;/font&gt;&lt;/p&gt;&lt;button class="btn btn-info" data-target="#demo" data-toggle="collapse" type="button"&gt;Note&lt;/button&gt;

&lt;div class="collapse" id="demo"&gt;&lt;font face="arial" size="4"&gt;For efficiency reasons, each module is only imported once per interpreter session.  Therefore, if you change your modules, you must restart the interpreter – or, if it’s just one module you want to test interactively, use &lt;code class="xref py py-func docutils literal notranslate"&gt;importlib.reload()&lt;/code&gt;, e.g. &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;import&lt;/span&gt; &lt;span class="pre"&gt;importlib;&lt;/span&gt; &lt;span class="pre"&gt;importlib.reload(modulename)&lt;/span&gt;&lt;/code&gt;.&lt;/font&gt;&lt;/div&gt;&lt;p&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;from pandas import Series&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;from pandas import DataFrame as df&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When a module prime is imported then python interpreter searches in the built-in modules first then it checks a file name prime.py in a list of directories given by &lt;/font&gt;&lt;font face="courier" size="4"&gt;sys.path.&lt;/font&gt;&lt;font face="arial" size="4"&gt;&amp;nbsp;The directories like current, default, or directory names with the same syntax as shell variable path.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;To load a module speedily python caches the module in &lt;/font&gt;&lt;font face="courier" size="4"&gt;__pycache__&lt;/font&gt;&lt;font face="arial" size="4"&gt; directory under the named &lt;/font&gt;&lt;font face="courier" size="4"&gt;module.version.pyc&lt;/font&gt;&lt;font face="arial" size="4"&gt; where the version indicates the format of the compiled file. For Example,&amp;nbsp;&lt;/font&gt;&lt;font face="courier" size="4"&gt;base_embed.cpython-38.pyc&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt; is the compiled file to load the modules fastly. &lt;/font&gt;&lt;font face="courier" size="4"&gt;__pycache__ &lt;/font&gt;&lt;font face="arial" size="4"&gt;is available in the&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/font&gt;&lt;font face="courier" size="4"&gt;\Python38Lib\site-packages\&lt;/font&gt;&lt;font face="arial" size="4"&gt; in this place.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Python checks the modification date of the source against the compiled version to see if it’s out of date and needs to be recompiled.  This is a completely automatic process.  Also, the compiled modules are platform-independent, so the same library can be shared among systems with different architectures.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Python does not check the cache in two circumstances.  First, it always recompiles and does not store the result for the module that’s loaded directly from the command line.  Second, it does not check the cache if there is no source module.  To support a non-source (compiled only) distribution, the compiled module must be in the source directory, and there must not be a source module.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;We discussed some of the &lt;a href="https://pythonbegginer.blogspot.com/2020/05/builtin-modules-in-python.html"&gt;standard modules &lt;/a&gt;in previous posts. The &lt;a href="https://pythonbegginer.blogspot.com/2020/05/virtual-environment-and-packages.html"&gt;virtual environment &lt;/a&gt;is also discussed in the previous posts&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;To use a module we need to know the functions or statements in that module. To know that use dir( ) built-in function which gives you the name of all the strings. import the module into your interpreter and use dir(modulename) to get all the methods. This is not only for modules and you can know about any object by using this function.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Packages are the way of structuring the Python's module namespace by using the dotted module names.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Here is a possible structure for a package.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/d97a93622dd1e6b45f4f35796c44fadb.js"&gt;&lt;/script&gt;
  &lt;script data-cfasync="false" src="//p384128.clksite.com/adServe/banners?tid=384128_788439_0" type="text/javascript"&gt;&lt;/script&gt;&lt;/font&gt;&lt;/div&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/3888551539557042444/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/module.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/3888551539557042444" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/3888551539557042444" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/module.html" rel="alternate" title="Modules in Python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0UEBwLFq_lBPgMQJnKT4LGTsN0W1iflAtsPSHG8lUwkW97Est6b7pF28ecdS_wxOjDqQFa3YhntDFeiwRkTHh9NqIsJvTYyDzNilVc4_s3goclTdW1INA97lkl_bKqkAuTuEYrj67nIc/s72-w640-h428-c/chris-ried-ieic5Tq8YMk-unsplash.jpg" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-555136179928569339</id><published>2020-06-08T10:06:00.001+05:30</published><updated>2020-06-08T10:06:36.481+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="dictionary"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Data Structures in Python - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;font face="arial" size="4"&gt;This post discusses some things you have learned about already in more detail and adds some new things as well.&lt;/font&gt;&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3uJyW-AFo8-LjHdXjpGNKJAzZ7W5CbppxR71TE4T_zOsXVyqJDV3Or4hRvNjaEDRQL7ngNqkhuL4qDeB3gLVX_zgbIW0lquxZ4P6-jAcKSDALiCw23OBTfZjRN3lQERzuJYGJIx-uPiA/s5184/shahadat-rahman-gnyA8vd3Otc-unsplash.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="3456" data-original-width="5184" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3uJyW-AFo8-LjHdXjpGNKJAzZ7W5CbppxR71TE4T_zOsXVyqJDV3Or4hRvNjaEDRQL7ngNqkhuL4qDeB3gLVX_zgbIW0lquxZ4P6-jAcKSDALiCw23OBTfZjRN3lQERzuJYGJIx-uPiA/w640-h426/shahadat-rahman-gnyA8vd3Otc-unsplash.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;Since Python is an evolving language, other sequence data types may be added. There is also another standard sequence data type: the&amp;nbsp;&lt;em&gt;&lt;a href="#tuple"&gt;tuple&lt;/a&gt;&lt;/em&gt;. List, the range is also the sequence data types. For data structures use sequence data types. &lt;a href="#sets"&gt;Sets&lt;/a&gt; and &lt;a href="#dictionary"&gt;dictionary&lt;/a&gt; are also sequence data types.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;span style="font-family: arial; font-size: xx-large;"&gt;&lt;b&gt;Lists&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The list is a versatile data type and can be changed if you apply operations on it because the list is a mutable object.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Here are some methods of list-objects.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;list.append(x)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Add an item to the end of a list. You can also add the element by&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&amp;gt;&amp;gt;&amp;gt; a[len(a):] = [x]&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;We discussed this kind of operation in the previous post of lists.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;list.insert(i,x)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Adding an element x at i &lt;sup&gt;th&lt;/sup&gt;&lt;/font&gt;&lt;font face="arial" size="4"&gt;&amp;nbsp;position. i is the index of the list, &lt;/font&gt;&lt;font face="courier" size="4"&gt;list.insert(0,x)&lt;/font&gt;&lt;font face="arial" size="4"&gt; means inserting the element x at first place. &lt;/font&gt;&lt;font face="courier" size="4"&gt;list.insert(len(a),x)&lt;/font&gt;&lt;font face="arial" size="4"&gt; means same as &lt;/font&gt;&lt;font face="courier" size="4"&gt;list.append(x).&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;list.remove(x)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;It will remove the first item with value x and raises the&lt;/font&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp;ValueError&lt;/font&gt;&lt;font face="arial" size="4"&gt; if there is no such value in the list.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;list.pop([i])&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Remove the item at the given position in the list, and return it.  If no index is specified, &lt;code class="docutils literal notranslate"&gt;a.pop()&lt;/code&gt; removes and returns the last item in the list.  (The square brackets around the &lt;i&gt;i&lt;/i&gt;&amp;nbsp;in the method signature denote that the parameter is optional, not that you should type square brackets at that position.  You will see this notation frequently in the Python Library Reference.). The statement del can also pop the last element from the list.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;del a[len(a)]&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;list.clear()&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;font face="arial"&gt;Removes all the elements from the list. same as &lt;/font&gt;&lt;font face="courier"&gt;del a[:].&lt;/font&gt;&lt;/font&gt;&lt;font face="arial" size="4"&gt;The &lt;code class="xref std std-keyword docutils literal notranslate"&gt;del&lt;/code&gt; statement can also be used to remove slices from a list or clear the entire list (which we did earlier by assignment of an empty list to the slice).&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;del a[2:4]&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;del a&amp;nbsp; #clears all the list&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;font face="courier"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;list.count(x)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Counts number of times x value is repeated in the list.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="arial" size="4"&gt;list.sort(&lt;/font&gt;&lt;font face="courier" size="4"&gt;key=None,reverse=False&lt;/font&gt;&lt;font face="arial" size="4"&gt;)&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Sort the items of the list in place. There is a sorted() method that takes the list as an argument.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;list.reverse()&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Reverses the elements in the list.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;list.copy()&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Returns a shallow copy of the list. Equivalent to a[ : ]&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;You can use a list as stacks.&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;It is also possible to use a list as a queue, where the first element added is the first element retrieved (“first-in, first-out”); however, lists are not efficient for this purpose.  While appends and pops from the end of the list are fast, doing inserts or pops from the beginning of a list is slow (because all of the other elements have to be shifted by one).&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;To implement a queue use collections.deque which was designed for fast appends and pops.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/de52dff53f1ad4be70a2cf9a3e38da83.js"&gt;&lt;/script&gt;
&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;List Comprehensions&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence or iterable or to create a subsequence of those elements that satisfy a certain condition.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;squares=[ ]&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;for x in range(10):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; squares.append(x*x)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;squares&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;[0,1,4,9,16,25,36,49,64,81]&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Note that this creates (or overwrites) a variable named &lt;code class="docutils literal notranslate"&gt;x&lt;/code&gt; that still exists after the loop completes.  We can calculate the list of squares without any side effects using:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;squares=[x**2 for x in range(10) ]&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;or&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;squares=list(map(lambda x : x**2 range(10)))&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;A list comprehension consists of brackets containing an expression followed by a &lt;code class="xref std std-keyword docutils literal notranslate"&gt;for&lt;/code&gt; clause, then zero or more &lt;code class="xref std std-keyword docutils literal notranslate"&gt;for&lt;/code&gt; or &lt;code class="xref std std-keyword docutils literal notranslate"&gt;if&lt;/code&gt; clauses.  The result will be a new list resulting from evaluating the expression in the context of the &lt;code class="xref std std-keyword docutils literal notranslate"&gt;for&lt;/code&gt; and &lt;code class="xref std std-keyword docutils literal notranslate"&gt;if&lt;/code&gt; clauses that follow it.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/06610aac1ebca24d37d905285a889d1d.js"&gt;&lt;/script&gt;
&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;List Comprehensions can have complex expressions and nested functions. We can also use nested list comprehensions.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;b&gt;&lt;font size="6"&gt;&lt;a href="#" id="tuple"&gt;Tuples&lt;/a&gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;b&gt;&lt;font size="6"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/c61eec89c88f81255a82f34cc62aabf4.js"&gt;&lt;/script&gt;&lt;font face="arial" size="4"&gt;As you see, on output tuples are always enclosed in parentheses, so that nested tuples are interpreted correctly; they may be input with or without surrounding parentheses, although often parentheses are necessary anyway (if the tuple is part of a larger expression). It is not possible to assign to the individual items of a tuple, however, it is possible to create tuples that contain mutable objects, such as lists&lt;/font&gt;.
&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;Though tuples may seem similar to lists, they are often used in different situations and for different purposes. Tuples are &lt;span class="xref std std-term"&gt;immutable&lt;/span&gt;, and usually contain a heterogeneous sequence of elements that are accessed via unpacking (see later in this section) or indexing (or even by attribute in the case of &lt;code class="xref py py-func docutils literal notranslate"&gt;namedtuples&lt;/code&gt;). Lists are &lt;span class="xref std std-term"&gt;mutable&lt;/span&gt;, and their elements are usually homogeneous and are accessed by iterating over the list.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;A special problem is the construction of tuples containing 0 or 1 items: the syntax has some extra quirks to accommodate these.  Empty tuples are constructed by an empty pair of parentheses; a tuple with one item is constructed by following a value with a comma (it is not sufficient to enclose a single value in parentheses). Ugly, but effective.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;empty = ( )&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;singleton = 'Python',&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;len(empty)&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;len(singleton)&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;1&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;In above code, singleton tuple takes python value into it but observes there is a comma when defining the tuple.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;The statement &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;t&lt;/span&gt; &lt;span class="pre"&gt;=&lt;/span&gt; &lt;span class="pre"&gt;12345,&lt;/span&gt; &lt;span class="pre"&gt;54321,&lt;/span&gt; &lt;span class="pre"&gt;'hello!'&lt;/span&gt;&lt;/code&gt; is an example of &lt;em&gt;tuple packing&lt;/em&gt;: the values &lt;code class="docutils literal notranslate"&gt;12345&lt;/code&gt;, &lt;code class="docutils literal notranslate"&gt;54321&lt;/code&gt; and &lt;code class="docutils literal notranslate"&gt;'hello!'&lt;/code&gt; are packed together in a tuple. The reverse operation is also possible&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;&amp;gt;&amp;gt;&amp;gt;x, y, z = t&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;This is called, appropriately enough, &lt;em&gt;sequence unpacking&lt;/em&gt; and works for any sequence on the right-hand side.  Sequence unpacking requires that there are as many variables on the left side of the equals sign as there are elements in the sequence.  Note that multiple assignments is really just a combination of tuple packing and sequence unpacking.&lt;/font&gt;&lt;/p&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;&lt;a href="#" id="sets"&gt;Sets&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;&lt;h2&gt;&lt;/h2&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;Python also includes a data type for &lt;em&gt;sets&lt;/em&gt;.  A set is an unordered collection with no duplicate elements.  Basic uses include membership testing and eliminating duplicate entries.  Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;Curly braces or the &lt;code class="xref py py-func docutils literal notranslate"&gt;set()&lt;/code&gt; function can be used to create sets.  Note: To create an empty set you have to use, not &lt;code class="docutils literal notranslate"&gt;{}&lt;/code&gt;;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/p&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/08376412283c0a584341494ffc89c1f9.js"&gt;&lt;/script&gt;&lt;font face="arial" size="4"&gt;Similarly to list comprehension, set comprehension is also possible.&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;&lt;a href="#" id="dictionary"&gt;Dictionary&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;Another useful data type built into Python is the &lt;em&gt;dictionary&lt;/em&gt;. Dictionaries are sometimes found in other languages as “associative memories” or “associative arrays”.  Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by &lt;em&gt;keys&lt;/em&gt;, which can be any immutable type; strings and numbers can always be keys.  Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key. You can’t use lists as keys since lists can be modified in place using index assignments, slice assignments, or methods like &lt;code class="xref py py-meth docutils literal notranslate"&gt;append()&lt;/code&gt; and &lt;code class="xref py py-meth docutils literal notranslate"&gt;extend()&lt;/code&gt;.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;It is best to think of a dictionary as a set of &lt;em&gt;key: value&lt;/em&gt; pairs, with the requirement that the keys are unique (within one dictionary). A pair of braces creates an empty dictionary: &lt;code class="docutils literal notranslate"&gt;{}&lt;/code&gt;. Placing a comma-separated list of key: value pairs within the braces add initial key: value pairs to the dictionary; this is also the way dictionaries are written on output.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;The main operations on a dictionary are storing a value with some key and extracting the value given the key.  It is also possible to delete a key: value pair with &lt;code class="docutils literal notranslate"&gt;del&lt;/code&gt;. If you store using a key that is already in use, the old value associated with that key is forgotten.  It is an error to extract a value using a non-existent key.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;Performing &lt;code class="docutils literal notranslate"&gt;list(d)&lt;/code&gt; on a dictionary returns a list of all the keys used in the dictionary, in insertion order (if you want it sorted, just use &lt;code class="docutils literal notranslate"&gt;sorted(d)&lt;/code&gt; instead). To check whether a single key is in the dictionary, use the &lt;code class="xref std std-keyword docutils literal notranslate"&gt;in&lt;/code&gt; keyword.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/p&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/1ffb625f598dd3e59c13d47c0cfe4d83.js"&gt;&lt;/script&gt;&lt;font face="arial" size="4"&gt;dict() constructor is used to create a dictionary directly from key-value pairs. In addition, dict comprehensions can be used to create dictionaries from arbitrary key and value expressions.&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;When the keys are simple strings, it is sometimes easier to specify pairs using keyword arguments&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/555136179928569339/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/datastructures-in-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/555136179928569339" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/555136179928569339" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/datastructures-in-python.html" rel="alternate" title="Data Structures in Python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3uJyW-AFo8-LjHdXjpGNKJAzZ7W5CbppxR71TE4T_zOsXVyqJDV3Or4hRvNjaEDRQL7ngNqkhuL4qDeB3gLVX_zgbIW0lquxZ4P6-jAcKSDALiCw23OBTfZjRN3lQERzuJYGJIx-uPiA/s72-w640-h426-c/shahadat-rahman-gnyA8vd3Otc-unsplash.jpg" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-5687709728169121555</id><published>2020-06-06T12:52:00.004+05:30</published><updated>2020-06-12T22:46:46.136+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Deep Copy"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="Shallow copy"/><title type="text">Difference between Shallow Copy and Deep Copy - LetsProgram</title><content type="html">&lt;font color="black"&gt;
 

&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;Before discussing the types of copying first we have to discuss the memory occupied by the datatypes in the system. We know that integer occupies 4 bytes, string occupies 4 bytes and float occupies 8 bytes. But what will python do when we have the same value stored with different variables will it allocate two spaces in the memory. id(variable_name) will give the number allocated to memory in the system.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;gt;&amp;gt;&amp;gt;x = 3&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;gt;&amp;gt;&amp;gt;y = x&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;gt;&amp;gt;&amp;gt;print(id(x),id(y))&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;140709828469200 140709828469200&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;The output id's of x and y are the same which means x and y are allocated in the same space. Python not created a different memory location for the new variable y&amp;nbsp;&lt;/span&gt;&lt;font face="arial" size="4"&gt;which has the same value as x.However, unlike "real" pointer like those in C and C++, things change, when we assign a new value to y. In these cases, y will receive a separate memory location.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In python, assignment operations will not create a new object but they create a link&amp;nbsp;&lt;/font&gt;&lt;span style="font-family: arial; font-size: large;"&gt;between the variable and the object.&amp;nbsp; When = operation is used user thinks a new&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: arial; font-size: large;"&gt;object is created but it only creates a new variable that shares the reference of the&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: arial; font-size: large;"&gt;original object. Sometimes, the user will work with the list (mutable objects) he will do many operations to it. sometimes a user wants copies that users can modify without&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: arial; font-size: large;"&gt;automatically modifying the original at the same time, in order to do that we create&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: arial; font-size: large;"&gt;copies of objects.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;This module does not &lt;font style="background-color: white;"&gt;copy&lt;/font&gt; types like module, method, stack trace, the stack frame, file, socket, window, array, or any similar types.  It does “&lt;font style="background-color: white;"&gt;copy&lt;/font&gt;” functions and classes (shallow and deeply), by returning the original object unchanged;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In python, there are two ways to copy.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;Deep Copy&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;Shallow Copy&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;Deep Copy&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In a deep copy, an object is copied into another object. It means that any changes made to the copy of the object are not observed in the original object. In python deep&amp;nbsp;&lt;/font&gt;&lt;span style="font-family: arial; font-size: large;"&gt;copy is done by using deepcopy() method from the copy module.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;copy.deepcopy(x[,memo])&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;will return the deep copy of x&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import copy&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;list1 = [ 1,2,3]&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;list2 = copy.deepcopy(list1)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;print(id(list1) , id(list2))&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;2638568131392 2638561816448&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;A deep copy constructs a new object and then insert the copies of&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;original into the new object recursively.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUl1Kx7CyfeJcjkXlgo5-x-wwoBXuVe1nyI1OzrV9uaVwB7gE6bvUD6QpFfd01h1qVGTSL5eHhntsONBWSy2BK4yPyrzrAVLYTeyInHopt4OKg26mUm8p9nCR9Zpug2xox-rRNvbanNlw/s1350/Deepcopy.png" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Deepcopy" border="0" data-original-height="506" data-original-width="1350" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUl1Kx7CyfeJcjkXlgo5-x-wwoBXuVe1nyI1OzrV9uaVwB7gE6bvUD6QpFfd01h1qVGTSL5eHhntsONBWSy2BK4yPyrzrAVLYTeyInHopt4OKg26mUm8p9nCR9Zpug2xox-rRNvbanNlw/w640-h240/Deepcopy.png" title="Deepcopy" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Two problems often exist with deep copy operations that don’t exist with shallow&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;copy operations:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;Recursive objects (compound objects that, directly or indirectly, contain a&amp;nbsp; &amp;nbsp; &amp;nbsp; reference to themselves) may cause a recursive loop.&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;Because deep copy copies everything it may copy too much, such as data that is intended to be shared between copies.&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;The &lt;code class="xref py py-func docutils literal notranslate"&gt;deepcopy()&lt;/code&gt; function avoids these problems by:&lt;/font&gt;&lt;/p&gt;&lt;ul class="simple"&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;keeping a &lt;code class="docutils literal notranslate"&gt;memo&lt;/code&gt; dictionary of objects already &lt;span style="background-color: white;"&gt;copied &lt;/span&gt;during the current &lt;span style="background-color: white;"&gt;copying &lt;/span&gt;pass; and&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;letting user-defined classes override the &lt;span style="background-color: white;"&gt;&lt;font&gt;copying&lt;/font&gt; &lt;/span&gt;operation or the set of components &lt;font style="background-color: white;"&gt;copied&lt;/font&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When we change the copy of the original object there will be no change in the original object.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/7da6a91d3b0cbf46190a7df5cb6faa68.js"&gt;&lt;/script&gt;
&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;Shallow Copy&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;A shallow copy means creating a new object and connecting the references with the original object.&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;The copying process does not recurse and therefore won’t create copies of the child objects themselves. In the case of shallow copy, a reference of the object is copied in other objects. It means that&amp;nbsp;&lt;/span&gt;&lt;strong style="background-color: white; border: 0px; color: rgba(0, 0, 0, 0.84); margin: 0px; padding: 0px; vertical-align: baseline;"&gt;any changes&lt;/strong&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&amp;nbsp;made to a copy of the object&amp;nbsp;&lt;/span&gt;&lt;strong style="background-color: white; border: 0px; color: rgba(0, 0, 0, 0.84); margin: 0px; padding: 0px; vertical-align: baseline;"&gt;do reflect&lt;/strong&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&amp;nbsp;in the original object. In python, this is implemented using the “&lt;/span&gt;&lt;strong style="background-color: white; border: 0px; color: rgba(0, 0, 0, 0.84); margin: 0px; padding: 0px; vertical-align: baseline;"&gt;copy()&lt;/strong&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;” function.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;copy.copy(x)&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;This will return the shallow copy of x&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import copy&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;list1 = [1,2,3,4,5]&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;list2 = copy.copy(list1)&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white;"&gt;&lt;font size="4"&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; print(id(list1),id(list2))&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;3027379129216 3027372888128&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiowKvq1lQJWUEN3nIAuILVpDzTno8Q5dG0kQnvnBN69cuFfgXfrxA3U8LcknJOFzwMgEum92-Kz5uBpK9dwHWlAoKbMwDEuhjyUPO_SJ9iLWgz0VOl2O31UMFR5LNjhs8mZlam8zqohPw/s1350/shallow.png" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Shallowcopy" border="0" data-original-height="506" data-original-width="1350" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiowKvq1lQJWUEN3nIAuILVpDzTno8Q5dG0kQnvnBN69cuFfgXfrxA3U8LcknJOFzwMgEum92-Kz5uBpK9dwHWlAoKbMwDEuhjyUPO_SJ9iLWgz0VOl2O31UMFR5LNjhs8mZlam8zqohPw/w640-h240/shallow.png" title="Shallowcopy" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;Even both the original and new objects are referring to the same values but the id's of both objects are different. This tells us both the objects are occupying different spaces in the memory.&lt;/div&gt;&lt;div style="font-family: arial;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;&lt;p style="border: 0px; color: rgba(0, 0, 0, 0.84); line-height: 1.71429; margin: 0px 0px 10px; padding: 0px; vertical-align: baseline;"&gt;&lt;font face="arial"&gt;The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances):&lt;/font&gt;&lt;/p&gt;&lt;ul style="border: 0px; color: rgba(0, 0, 0, 0.84); line-height: 1.71429; list-style-image: initial; list-style-position: outside; margin: 0px 0px 24px; padding: 0px; text-align: justify; vertical-align: baseline;"&gt;&lt;li style="border: 0px; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;"&gt;&lt;font face="arial"&gt;A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original.&lt;/font&gt;&lt;/li&gt;&lt;li style="border: 0px; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;"&gt;&lt;font face="arial"&gt;A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original.&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;
&lt;script type="text/javascript"&gt;
	atOptions = {
		'key' : '1a74462f31536a9f0b04b08cb4d332cc',
		'format' : 'iframe',
		'height' : 90,
		'width' : 320,
		'params' : {}
	};
	document.write('&lt;scr' + 'ipt type="text/javascript" src="http' + (location.protocol === 'https:' ? 's' : '') + '://www.bestdisplayformats.com/1a74462f31536a9f0b04b08cb4d332cc/invoke.js"&gt;&lt;/scr' + 'ipt&gt;');
&lt;/script&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/5687709728169121555/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/shallow-copy-and-deep-copy.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/5687709728169121555" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/5687709728169121555" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/shallow-copy-and-deep-copy.html" rel="alternate" title="Difference between Shallow Copy and Deep Copy - LetsProgram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUl1Kx7CyfeJcjkXlgo5-x-wwoBXuVe1nyI1OzrV9uaVwB7gE6bvUD6QpFfd01h1qVGTSL5eHhntsONBWSy2BK4yPyrzrAVLYTeyInHopt4OKg26mUm8p9nCR9Zpug2xox-rRNvbanNlw/s72-w640-h240-c/Deepcopy.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-6839574680023444266</id><published>2020-06-02T11:31:00.002+05:30</published><updated>2020-06-02T11:32:36.093+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="RegEx"/><title type="text">RegEx in Python - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;div&gt;&lt;font face="arial" size="4"&gt;Regular expressions (called REs, or regexes, or regex patterns) are essentially a tiny, highly specialized programming language embedded inside Python and made available through the &lt;a class="reference internal" href="mk:@MSITStore:C:\Python38\Doc\python383rc1.chm::/library/re.html#module-re" title="re: Regular expression operations."&gt;&lt;code class="xref py py-mod docutils literal notranslate"&gt;&lt;span class="pre"&gt;&lt;font color="#ffffff" style="background-color: #0078d7;"&gt;re&lt;/font&gt;&lt;/span&gt;&lt;/code&gt;&lt;/a&gt; module. Using this little language, you specify the rules for the set of possible strings that you want to match; this set might contain English sentences, or e-mail addresses, or TeX commands, or anything you like.  You can then ask questions such as “Does this string match the pattern?”, or “Is there a match for the pattern anywhere in this string?”.  You can also use REs to modify a string or to split it apart in various ways.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTgje7Tewyc91Zs2dc_aoyYv4ak6WCglps0HMoTUegyhhuSyIjH1dDXi0_RZcAT8KcehkZLVXWyEvw-sFjJVTCuTXPKKE7eWiAAYPSBCS5xWphhpZlJC4Ib9QDWnhku1JPPlCxNSPFftI/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Finding pattrens in the string" border="0" data-original-height="2666" data-original-width="3999" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTgje7Tewyc91Zs2dc_aoyYv4ak6WCglps0HMoTUegyhhuSyIjH1dDXi0_RZcAT8KcehkZLVXWyEvw-sFjJVTCuTXPKKE7eWiAAYPSBCS5xWphhpZlJC4Ib9QDWnhku1JPPlCxNSPFftI/w640-h426/markus-winkler-BvlxNyjnIzg-unsplash.jpg" title="Finding pattrens in the string" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;A RegEx or Regular Expression is a sequence of characters to search for a pattern.&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;RegEx is used to check if a string had any specified pattern in it.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Python had a RegEx &lt;a href="https://pythonbegginer.blogspot.com/2020/05/builtin-modules-in-python.html"&gt;module&lt;/a&gt; called &lt;/font&gt;&lt;font face="courier" size="4"&gt;re&lt;/font&gt;&lt;font face="arial" size="4"&gt; which is used to work for regular Expressions. Import the re module into the python.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import re&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;Regex Functions&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;re module had a set of functions that deal with regular expressions.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;table border="1" bordercolor="#888" cellspacing="0" style="border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="min-width: 60px;"&gt;&lt;b&gt;&lt;font size="4"&gt;&amp;nbsp;Function&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;b&gt;&lt;font size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Description&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;/b&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;font size="4"&gt;findall&lt;br /&gt;&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a list containing all the matches.&lt;br /&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;search&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a Match object if there is any match in the string.&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;split&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a list where the string has been split at every match.&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;sub&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Replaces one or many strings.&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;finditer&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Find all substrings where the RE matches and returns them as an Iterator&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;match&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Determine if the RE matches at the beginning of the string.&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;MetaCharacters&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;MetaCharacters are the characters that have special meaning in the RegEx.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;table border="1" bordercolor="#888" cellspacing="0" style="border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="min-width: 60px;"&gt;&amp;nbsp;&lt;b&gt;&lt;font size="4"&gt;Character&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;b&gt;&lt;font size="4"&gt;&amp;nbsp;Description&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;b&gt;&lt;font size="4"&gt;Example&amp;nbsp;&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;font size="4"&gt;[ ]&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;A set of characters&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"[a-m]"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;\&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Signals a special sequence (can also be used to escape special characters)&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"\d"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;.&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Any character (except newline character)&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"he..o"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;^&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Starts with&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"^hello"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;$&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Ends with&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"world$"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;*&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Zero or more occurrences&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"aix*"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;+&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;One or more occurrences&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"aix+"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;{ }&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Exactly the specified number of occurrences&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"al{2}"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;|&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Either or&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"falls|stays"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="min-width: 60px;"&gt;&lt;font size="4"&gt;&amp;nbsp;( )&lt;/font&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;font size="4"&gt;&amp;nbsp;Capture and Group&lt;/font&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;font size="4"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;p&gt;&lt;font face="arial" size="4" style="font-weight: normal;"&gt;The first metacharacters we’ll look at are &lt;code class="docutils literal notranslate"&gt;[&lt;/code&gt; and &lt;code class="docutils literal notranslate"&gt;]&lt;/code&gt;. They’re used for specifying a character class, which is a set of characters that you wish to match.  Characters can be listed individually, or a range of characters can be indicated by giving two characters and separating them by a &lt;code class="docutils literal notranslate"&gt;'-'&lt;/code&gt;.  For example, &lt;code class="docutils literal notranslate"&gt;[abc]&lt;/code&gt; will match any of the characters &lt;code class="docutils literal notranslate"&gt;a&lt;/code&gt;, &lt;code class="docutils literal notranslate"&gt;b&lt;/code&gt;, or &lt;code class="docutils literal notranslate"&gt;c&lt;/code&gt;; this is the same as &lt;code class="docutils literal notranslate"&gt;[a-c]&lt;/code&gt;, which uses a range to express the same set of characters.  If you wanted to match only lowercase letters, your RE would be &lt;code class="docutils literal notranslate"&gt;[a-z]&lt;/code&gt;.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4" style="font-weight: normal;"&gt;Metacharacters are not active inside classes.  For example, &lt;code class="docutils literal notranslate"&gt;[akm$]&lt;/code&gt; will match any of the characters &lt;code class="docutils literal notranslate"&gt;'a'&lt;/code&gt;, &lt;code class="docutils literal notranslate"&gt;'k'&lt;/code&gt;, &lt;code class="docutils literal notranslate"&gt;'m'&lt;/code&gt;, or &lt;code class="docutils literal notranslate"&gt;'$'&lt;/code&gt;; &lt;code class="docutils literal notranslate"&gt;'$'&lt;/code&gt; is usually a metacharacter, but inside a character class, it’s stripped of its special nature.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4" style="font-weight: normal;"&gt;You can match the characters not listed within the class by &lt;em class="dfn"&gt;complementing&lt;/em&gt; the set.  This is indicated by including a &lt;code class="docutils literal notranslate"&gt;'^'&lt;/code&gt; as the first character of the class. For example, &lt;code class="docutils literal notranslate"&gt;[^5]&lt;/code&gt; will match any character except &lt;code class="docutils literal notranslate"&gt;'5'&lt;/code&gt;.  If the caret appears elsewhere in a character class, it does not have special meaning. For example: &lt;code class="docutils literal notranslate"&gt;[5^]&lt;/code&gt; will match either a &lt;code class="docutils literal notranslate"&gt;'5'&lt;/code&gt; or a &lt;code class="docutils literal notranslate"&gt;'^'&lt;/code&gt;.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4" style="font-weight: normal;"&gt;Perhaps the most important metacharacter is the backslash, &lt;code class="docutils literal notranslate"&gt;\&lt;/code&gt;.   As in Python string literals, the backslash can be followed by various characters to signal various special sequences.  It’s also used to escape all the metacharacters so you can still match them in patterns; for example, if you need to match a &lt;code class="docutils literal notranslate"&gt;[&lt;/code&gt; or  &lt;code class="docutils literal notranslate"&gt;\&lt;/code&gt;, you can precede them with a backslash to remove their special meaning: &lt;code class="docutils literal notranslate"&gt;\[&lt;/code&gt; or &lt;code class="docutils literal notranslate"&gt;\\&lt;/code&gt;.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4" style="font-weight: normal;"&gt;Some of the special sequences beginning with &lt;code class="docutils literal notranslate"&gt;'\'&lt;/code&gt; represent predefined sets of characters that are often useful, such as the set of digits, the set of letters, or the set of anything that isn’t whitespace.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: normal;"&gt;&lt;font face="arial" size="4"&gt;Regular expressions are compiled into pattern objects, which have methods for various operations such as searching for pattern matches or performing string substitute.&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;code class="xref py py-func docutils literal notranslate" style="font-weight: normal;"&gt;re.compile()&lt;/code&gt;&lt;span style="font-family: arial; font-size: large; font-weight: normal;"&gt; also accepts an optional &lt;/span&gt;&lt;em style="font-family: arial; font-size: large; font-weight: normal;"&gt;flags&lt;/em&gt;&lt;span style="font-family: arial; font-size: large; font-weight: normal;"&gt; argument, used to enable various special features and syntax variations.  We’ll go over the available settings later, but for now, a single example will do:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: large;"&gt;&lt;font face="courier"&gt;&amp;gt;&amp;gt;&amp;gt;p=re.compile('ab*',re.IGNORECASE)&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;/h3&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;Special Sequence&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;A special sequence is \ followed by one of the characters below. Which have a special meaning to it.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;table border="1" bordercolor="#888" cellspacing="0" style="border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="min-width: 60px;"&gt;&lt;b&gt;&lt;font size="4"&gt;Char&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;b&gt;&lt;font size="4"&gt;Description&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;b&gt;&lt;font size="4"&gt;Example&lt;/font&gt;&lt;/b&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="min-width: 60px;"&gt;&lt;font size="4"&gt;&amp;nbsp;\A&lt;/font&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a match if the specified characters are at the beginning of the string&lt;/font&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;font size="4"&gt;&amp;nbsp;"\AThe"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;\b&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a match where the specified characters are at the beginning or at the end of a word&lt;br style="background-color: white; box-sizing: inherit; font-family: verdana, sans-serif;" /&gt;&lt;span style="background-color: white; font-family: verdana, sans-serif;"&gt;(the "r" in the beginning is making sure that the string is being treated as a "raw string")&lt;/span&gt;&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;r"\bair"&lt;br /&gt;&amp;nbsp;r"air\b"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;\B&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&lt;span style="background-color: #f1f1f1; font-family: verdana, sans-serif;"&gt;Returns a match where the specified characters are present, but NOT at the beginning (or at the end) of a word&lt;/span&gt;&lt;br style="background-color: #f1f1f1; box-sizing: inherit; font-family: verdana, sans-serif;" /&gt;&lt;span style="background-color: #f1f1f1; font-family: verdana, sans-serif;"&gt;(the "r" in the beginning is making sure that the string is being treated as a "raw string")&lt;/span&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp; r"\Bair"&lt;br /&gt;&amp;nbsp; r"air\B"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;\d&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a match where the string contains digits (numbers from 0-9)&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"\d"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;\D&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a match where the string DOES NOT contain digits&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"\D"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;\s&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a match where the string contains a white space character&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"\s"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;\S&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a match where the string DOES NOT contain a white space character&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"\S"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;\w&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a match where the string contains any word characters (characters from a to Z, digits from 0-9, and the underscore _ character)&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"\w"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;\W&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a match where the string DOES NOT contain any word characters&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"\W"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;\Z&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Returns a match if the specified characters are at the end of the string&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;"spain\Z"&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import re&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;p=re.compile("[a-z]+")&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;p&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;re.compile('[a-z]+')&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;str="what is what ?"&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;p.match(str)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;lt;re.Match object; span=(0, 4), match='what'&amp;gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Now you can query the &lt;span class="std std-ref"&gt;match object&lt;/span&gt; for information about the matching string.  Match object instances also have several methods and attributes; the most important ones are:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;table border="1" bordercolor="#888" cellspacing="0" style="border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&lt;b&gt;&amp;nbsp;Method/Attribute&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&lt;b&gt;Purpose&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;group&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Return the string matched by the RE&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;start&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font size="4"&gt;&amp;nbsp;Return the starting position of the match&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="min-width: 60px;"&gt;&lt;font size="4"&gt;&amp;nbsp;end&lt;/font&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;font size="4"&gt;&amp;nbsp;Return the ending position of the match&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="min-width: 60px;"&gt;&lt;font size="4"&gt;&amp;nbsp;span&lt;/font&gt;&lt;/td&gt;&lt;td style="min-width: 60px;"&gt;&lt;font size="4"&gt;&amp;nbsp;Return a tuple containing the (start, end) positions  of the match&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;gt;&amp;gt;&amp;gt; m = p.match(str)&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;gt;&amp;gt;&amp;gt; m.group()&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier"&gt;'what'&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;gt;&amp;gt;&amp;gt; m.start()&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier"&gt;0&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;gt;&amp;gt;&amp;gt; m.end()&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier"&gt;4&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;gt;&amp;gt;&amp;gt; m.span()&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier"&gt;(0, 4)&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;&lt;code class="xref py py-meth docutils literal notranslate"&gt;group()&lt;/code&gt; returns the substring that was matched by the RE.  &lt;code class="xref py py-meth docutils literal notranslate"&gt;start()&lt;/code&gt; and &lt;code class="xref py py-meth docutils literal notranslate"&gt;end()&lt;/code&gt; return the starting and ending index of the match. &lt;code class="xref py py-meth docutils literal notranslate"&gt;span()&lt;/code&gt; returns both start and end indexes in a single tuple.  Since the &lt;code class="xref py py-meth docutils literal notranslate"&gt;match()&lt;/code&gt; method only checks if the RE matches at the start of a string, &lt;code class="xref py py-meth docutils literal notranslate"&gt;start()&lt;/code&gt;&amp;nbsp;it will always be zero.  However, the &lt;code class="xref py py-meth docutils literal notranslate"&gt;search()&lt;/code&gt; method of patterns scans through the string, so the match may not start at zero in that case.&lt;/div&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;p = re.compile(r'\d+')&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;p.findall("on day 12 i spend 50 rupees")&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;["12","50"]&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;code class="xref py py-meth docutils literal notranslate"&gt;findall()&lt;/code&gt; has to create the entire list before it can be returned as the result.  The &lt;code class="xref py py-meth docutils literal notranslate"&gt;finditer()&lt;/code&gt;&amp;nbsp;the method returns a sequence of &lt;span class="std std-ref"&gt;match object&lt;/span&gt; instances as an &lt;span class="xref std std-term"&gt;&lt;a class="reference internal" href="https://pythonbegginer.blogspot.com/2020/05/iterators-and-generators-in-python.html"&gt;iterator&lt;/a&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;With the help of metacharacters and special sequences, we can do RegEx operations easily.&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/6839574680023444266/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/regex-in-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6839574680023444266" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6839574680023444266" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/06/regex-in-python.html" rel="alternate" title="RegEx in Python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTgje7Tewyc91Zs2dc_aoyYv4ak6WCglps0HMoTUegyhhuSyIjH1dDXi0_RZcAT8KcehkZLVXWyEvw-sFjJVTCuTXPKKE7eWiAAYPSBCS5xWphhpZlJC4Ib9QDWnhku1JPPlCxNSPFftI/s72-w640-h426-c/markus-winkler-BvlxNyjnIzg-unsplash.jpg" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-4774196671052710788</id><published>2020-05-31T15:55:00.002+05:30</published><updated>2020-06-01T22:03:56.244+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="modules"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Standard library modules in Python - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;font face="arial" size="4"&gt;In python, there are some packages installed. These will come by default when you are downloading the software. There are many of them you can see the list here:&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;a href="https://docs.python.org/3/py-modindex.html" target="_blank"&gt;Module index&lt;/a&gt;.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Here we discuss some of the modules which are very useful to a programmer now.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
&lt;script&gt;
$(document).ready(function(){
  $("button").click(function(){
    $("#a").toggle();
  });
});
&lt;/script&gt;
&lt;style&gt;
#font{
color: black;
padding: 40px;
font-size:300%;
}
.bookmark{
background-color:lavender;
}
&lt;/style&gt;
&lt;div class="bookmark" style="border: 2px solid black;"&gt;
&lt;span id="font"&gt;&lt;b&gt;&lt;font face="arial" size="6"&gt;PageContents&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;
&lt;button class="btn btn-primary" type="button"&gt;&lt;span class="glyphicon glyphicon-th-list"&gt;&lt;/span&gt;&lt;/button&gt;
&lt;p&gt;&lt;/p&gt;&lt;h4&gt;&lt;font face="arial"&gt;&lt;span style="font-weight: 400;"&gt;&amp;nbsp; Modules of python that are discussed in this post.&lt;/span&gt;&lt;/font&gt;&lt;/h4&gt;&lt;p&gt;&lt;/p&gt;
&lt;ol id="a" type="1"&gt;
&lt;li&gt;&lt;a href="#Operating System Interface"&gt;&lt;h4&gt;&lt;font color="black" face="arial"&gt;Operating System Interface&lt;/font&gt;&lt;/h4&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#commandline"&gt;&lt;h4&gt;&lt;font color="black" face="arial"&gt;Command-line Arguments&lt;/font&gt;&lt;/h4&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#regex"&gt;&lt;h4&gt;&lt;font color="black" face="arial"&gt;Regular Expression&lt;/font&gt;&lt;/h4&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#maths"&gt;&lt;h4&gt;&lt;font color="black" face="arial"&gt;Maths&lt;/font&gt;&lt;/h4&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#internet"&gt;&lt;h4&gt;&lt;font color="black" face="arial"&gt;Internet Access&lt;/font&gt;&lt;/h4&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#date"&gt;&lt;h4&gt;&lt;font color="black" face="arial"&gt;Dates and Times&lt;/font&gt;&lt;/h4&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#data"&gt;&lt;h4&gt;&lt;font color="black" face="arial"&gt;Data Comprehension&lt;/font&gt;&lt;/h4&gt;&lt;/a&gt;&lt;/li&gt;
  
&lt;/ol&gt;
&lt;/div&gt;
&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;h2 style="text-align: left;"&gt;&lt;font color="#b51200" face="arial" size="6"&gt;&lt;a color="black" href="#" id="Operating System Interface" style="background-color: white; color: black;"&gt;Operating System Interface&lt;/a&gt;&lt;/font&gt;&lt;/h2&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Python can also interact with the operating system you are using. For a different operating system, different python software will be available so there is no problem in accessing the python.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The os module will provide dozens of commands to interact with the operating system.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If you want to write or read files you can use &lt;/font&gt;&lt;font face="courier" size="4"&gt;open() &lt;/font&gt;&lt;font face="arial" size="4"&gt;method, manipulate paths using &lt;/font&gt;&lt;font face="courier" size="4"&gt;os.path&lt;/font&gt;&lt;font face="arial" size="4"&gt; module, create a file, or a directory using &lt;/font&gt;&lt;font face="courier" size="4"&gt;shutil&lt;/font&gt;&lt;font face="arial" size="4"&gt; module.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;All the functions in this module will raise OSError in case of invalid or inaccessible file or path names.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div class="row"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import os&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;os.getcwd()&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;'C:\\python38'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;os.chdir('\system\files\')&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;os.system('mkdir programs')&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;getcwd()&lt;/font&gt;&lt;font face="arial" size="4"&gt; will give you the current working directory of the system. &lt;/font&gt;&lt;font face="courier" size="4"&gt;chdir()&lt;/font&gt;&lt;font face="arial" size="4"&gt; will change you the path of the current directory. &lt;/font&gt;&lt;font face="courier" size="4"&gt;system()&lt;/font&gt;&lt;font face="arial" size="4"&gt; will be used as a shell you can give any commands.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;For file and directory management tasks &lt;/font&gt;&lt;font face="courier" size="4"&gt;shutil&lt;/font&gt;&lt;font face="arial" size="4"&gt; module will provide you an interface which is easy to use.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div class="container"&gt;&lt;div class="row"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import shutil&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;shutil.copyfile('data.db','archive.db')&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;'archive.db'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;shutil.move('/users/programs','Python38')&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;'Python38'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Be sure you use &lt;/font&gt;&lt;font color="#ffffff" face="courier" size="4"&gt;&lt;b style="background-color: black;"&gt;import os&lt;/b&gt;&lt;/font&gt;&lt;font face="arial" size="4"&gt; style instead of &lt;/font&gt;&lt;font color="#ffffff" face="courier" size="4" style="background-color: black;"&gt;&lt;b&gt;from os import *&lt;/b&gt;&lt;/font&gt;&lt;font face="arial" size="4"&gt;. This will make &lt;/font&gt;&lt;font face="courier" size="4"&gt;os.open()&lt;/font&gt;&lt;font face="arial" size="4"&gt; from shadowing the built-in function &lt;/font&gt;&lt;font face="courier" size="4"&gt;open() &lt;/font&gt;&lt;font face="arial" size="4"&gt;which are different.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;To know all the module functions use the command &lt;/font&gt;&lt;font face="courier" size="4"&gt;dir(os)&lt;/font&gt;&lt;font face="arial" size="4"&gt; and to know the module's docstring use the command &lt;/font&gt;&lt;font face="courier" size="4"&gt;help(os)&lt;/font&gt;&lt;font face="arial" size="4"&gt;.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;h2 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;&lt;a href="#" id="commandline" style="color: black;"&gt;Command-line Arguments&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;&lt;/h2&gt;&lt;div&gt;&lt;font face="arial" size="6"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Common utility scripts often need to process command-line arguments. These arguments are stored in the &lt;code class="xref py py-mod docutils literal notranslate"&gt;sys&lt;/code&gt; module’s &lt;em&gt;argv&lt;/em&gt; attribute as a list.  For instance the following output results from running&lt;/font&gt;&lt;font size="4"&gt;&lt;font face="courier"&gt; &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;python&lt;/span&gt; &lt;span class="pre"&gt;demo.py&lt;/span&gt; &lt;span class="pre"&gt;one&lt;/span&gt; &lt;span class="pre"&gt;two&lt;/span&gt; &lt;span class="pre"&gt;three&lt;/span&gt;&lt;/code&gt;&lt;/font&gt;&lt;font face="arial"&gt; at the command line:&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier" size="4"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/font&gt;&lt;/b&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt; import sys&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;print(sys.argv)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;['demo.py','one','two','&lt;/b&gt;&lt;/font&gt;&lt;b style="font-family: courier; font-size: large;"&gt;three'&lt;/b&gt;&lt;b style="font-family: courier; font-size: large;"&gt;]&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The &lt;code class="xref py py-mod docutils literal notranslate"&gt;argparse&lt;/code&gt; module provides a more sophisticated mechanism to process command line arguments.  The following script extracts one or more filenames and an optional number of lines to be displayed:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/93c21cdf704d22b6ac6c2ed61c643696.js"&gt;&lt;/script&gt;&lt;font face="arial" size="4"&gt;When run at the command line with &lt;/font&gt;&lt;font face="courier" size="4"&gt;python top.py --lines=5 alpha.txt beta.txt&lt;/font&gt;&lt;font face="arial" size="4"&gt;, the script sets &lt;/font&gt;&lt;font face="courier" size="4"&gt;args.lines &lt;/font&gt;&lt;font face="arial" size="4"&gt;to 5 and &lt;/font&gt;&lt;font face="courier" size="4"&gt;args.filenames&lt;/font&gt;&lt;font face="arial" size="4"&gt; to &lt;/font&gt;&lt;font face="courier" size="4"&gt;['alpha.txt', 'beta.txt'].&lt;/font&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;h2 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;&lt;a href="#" id="regex" style="color: black;"&gt;Regular Expression&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;&lt;/h2&gt;&lt;div&gt;&lt;font face="arial" size="6"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The &lt;a class="reference internal" href="mk:@MSITStore:C:\Python38\Doc\python383rc1.chm::/library/re.html#module-re" title="re: Regular expression operations."&gt;&lt;code class="xref py py-mod docutils literal notranslate"&gt;re&lt;/code&gt;&lt;/a&gt; module provides regular expression tools for advanced string processing. For complex matching and manipulation, regular expressions offer succinct, optimized solutions:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;import re&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;re.findall(r'bd[a-z]*',&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;"Follow the blog for more updates")&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;['Follow','for']&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&lt;font size="4"&gt;&amp;gt;&amp;gt;&amp;gt;re.sub(r'(\b[a-z]+) \1', r'\1',&lt;/font&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&lt;font size="4"&gt;&amp;nbsp;'cat in the the hat'&lt;/font&gt;&lt;span style="font-size: large;"&gt;)&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;'cat in the hat'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When only simple capabilities are needed, string methods are preferred because they are easier to read and debug:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;"Tickets for two".replace('two','us')&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;'Tickets for us'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;h2 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;&lt;a href="#" id="maths" style="color: black;"&gt;Maths&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;&lt;/h2&gt;&lt;div&gt;&lt;font face="arial" size="6"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The &lt;a class="reference internal" href="mk:@MSITStore:C:\Python38\Doc\python383rc1.chm::/library/math.html#module-math" title="math: Mathematical functions (sin() etc.)."&gt;&lt;code class="xref py py-mod docutils literal notranslate"&gt;math&lt;/code&gt;&lt;/a&gt; module gives access to the underlying C library functions for floating-point math:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&amp;gt;&amp;gt;&amp;gt;import math&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&amp;gt;&amp;gt;&amp;gt;math.cos(math.pi/4)&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;0.707016&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&amp;gt;&amp;gt;&amp;gt;math.log(1024,2)&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;10&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The &lt;a class="reference internal" href="mk:@MSITStore:C:\Python38\Doc\python383rc1.chm::/library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."&gt;&lt;code class="xref py py-mod docutils literal notranslate"&gt;random&lt;/code&gt;&lt;/a&gt; module provides tools for making random selections and&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;The &lt;a class="reference internal" href="mk:@MSITStore:C:\Python38\Doc\python383rc1.chm::/library/statistics.html#module-statistics" title="statistics: Mathematical statistics functions"&gt;&lt;code class="xref py py-mod docutils literal notranslate"&gt;statistics&lt;/code&gt;&lt;/a&gt; module calculates basic statistical properties (the mean, median, variance, etc.) of numeric data:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/405fe118d36fb80b9a840c37572e140c.js"&gt;&lt;/script&gt;&lt;font face="arial" size="4"&gt;
The SciPy project&amp;nbsp;&lt;https: scipy.org=""&gt;has many other modules for numerical computations.
&lt;/https:&gt;&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;https: scipy.org=""&gt;&lt;br /&gt;&lt;/https:&gt;&lt;/font&gt;&lt;/div&gt;&lt;h2 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;https: scipy.org=""&gt;&lt;b&gt;&lt;a href="#" id="internet" style="color: black;"&gt;Internet Access&lt;/a&gt;&lt;/b&gt;&lt;/https:&gt;&lt;/font&gt;&lt;/h2&gt;&lt;div&gt;&lt;font face="arial" size="6"&gt;&lt;https: scipy.org=""&gt;&lt;br /&gt;&lt;/https:&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;There are a number of modules for accessing the internet and processing internet protocols. Two of the simplest are &lt;a class="reference internal" href="mk:@MSITStore:C:\Python38\Doc\python383rc1.chm::/library/urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."&gt;&lt;code class="xref py py-mod docutils literal notranslate"&gt;urllib.request&lt;/code&gt;&lt;/a&gt; for retrieving data from URLs and &lt;a class="reference internal" href="mk:@MSITStore:C:\Python38\Doc\python383rc1.chm::/library/smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."&gt;&lt;code class="xref py py-mod docutils literal notranslate"&gt;smtplib&lt;/code&gt;&lt;/a&gt; for sending mail:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/e3ecc1194d564c378be73c4308e49442.js"&gt;&lt;/script&gt;&lt;h2 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;a href="#" id="date" style="color: black;"&gt;Dates and Times&lt;/a&gt;&lt;/font&gt;&lt;/h2&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The &lt;a class="reference internal" href="mk:@MSITStore:C:\Python38\Doc\python383rc1.chm::/library/datetime.html#module-datetime" title="datetime: Basic date and time types."&gt;&lt;code class="xref py py-mod docutils literal notranslate"&gt;datetime&lt;/code&gt;&lt;/a&gt; module supplies classes for manipulating dates and times in both simple and complex ways. While date and time arithmetic is supported, the focus of the implementation is on efficient member extraction for output formatting and manipulation.  The module also supports objects that are timezone aware.&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/b05c22137e33e9a2bf19b99e3afe79cc.js"&gt;&lt;/script&gt;&lt;h2 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;a href="#" id="data" style="color: black;"&gt;Data Comprehension&lt;/a&gt;&lt;/font&gt;&lt;/h2&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;font face="arial"&gt;Common data archiving and compression formats are directly supported by modules including:&amp;nbsp;&lt;/font&gt;&lt;font face="courier"&gt;zlib, gzip, bz2, lzma, zipfile &lt;/font&gt;&lt;font face="arial"&gt;and&lt;/font&gt;&lt;font face="courier"&gt; tarfile.&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; import zlib&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; s = b'witch which has which witches wrist watch'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp;&amp;gt;&amp;gt;&amp;gt; len(s)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp;41&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp;&amp;gt;&amp;gt;&amp;gt; t = zlib.compress(s)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp;&amp;gt;&amp;gt;&amp;gt; len(t)&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;37&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; zlib.decompress(t)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;b'witch which has which witches wrist watch'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp;&amp;gt;&amp;gt;&amp;gt; zlib.crc32(s)&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;226805979&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/4774196671052710788/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/builtin-modules-in-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/4774196671052710788" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/4774196671052710788" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/builtin-modules-in-python.html" rel="alternate" title="Standard library modules in Python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-7976033038231283339</id><published>2020-05-29T17:14:00.006+05:30</published><updated>2020-05-30T16:52:09.623+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="pip"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="virtual environment"/><title type="text">Virtual environment and Packages - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;font face="arial" size="4"&gt;The virtual environment is a good practice for coding applications. Python applications use packages and modules which are not from the standard library. Sometimes an application needs a specific version of the package or module to repair a bug.&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;This means it may not be possible for one Python installation to meet the requirements of every application.  If application A needs version 1.x of a particular module but application B needs version 2.y, then the requirements are in conflict, and installing either version 1.x or 2.y will leave one application unable to run.&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Here we use a virtual environment&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;self-contained directory tree that contains a Python installation for a particular version of Python, plus several additional packages. each application, you can use a different virtual environment and make your work easier.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;Create a Virtual Environment&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If you are using Python3 then you will already have venv in your system otherwise you should install it by using the pip command in the shell&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;python -m pip install&amp;nbsp; virtualenvwrapper-win&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Create a directory where you want to work with&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;mkdir&amp;nbsp; foldername&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;create a virtual environment there by running venv module as a script with the directory module.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;mkvirtualenv&amp;nbsp; name&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;This will create a virtual environment with a name as 'name'. After creating the environment you can work specifically on your application.&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRfJOj6hAn39SCYAUA5IPdnFWpTIUUM-F2FhvqqZQMCVJEqeQP20bfRFiHUOA8ieGwUTjFZC1h-DUgVc-itR_-Ug7FdOSw6YqLZfZnK9wVdZ4OhkiOEdSxWZ_yDsb0hAYaZkkSBdtvd_A/" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Virtual environment and packages" border="0" data-original-height="647" data-original-width="1906" height="218" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRfJOj6hAn39SCYAUA5IPdnFWpTIUUM-F2FhvqqZQMCVJEqeQP20bfRFiHUOA8ieGwUTjFZC1h-DUgVc-itR_-Ug7FdOSw6YqLZfZnK9wVdZ4OhkiOEdSxWZ_yDsb0hAYaZkkSBdtvd_A/w640-h218/Screenshot+%252854%2529.png" title="Virtual environment and packages" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;p style="background-color: black; color: white;"&gt;&lt;font face="arial" size="4"&gt;Note: When you restart your shell your virtual environment will be closed you have to restart it with the respective command to again start your virtual environment.&lt;/font&gt;&lt;/p&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;h3 style="text-align: left;"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;Manage packages using pip&lt;/b&gt;&lt;/font&gt;&lt;/h3&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;You can install, upgrade, and also remove the packages using &lt;a href="https://pip.pypa.io/en/stable/installing/" target="_blank"&gt;pip&lt;/a&gt; command. By default, pip will install the packages from the python index. pip can also be used to search the packages from the python index, it will give you package name and version with it.&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;pip has many commands like install, uninstall, freeze, search, etc.(Go through the &lt;a href="https://pip.pypa.io/en/stable/installing/" target="_blank"&gt;installing pip&lt;/a&gt; for more information)&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;code&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;pip install django&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;pip install django == 3.0.6&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;pip install --upgrade django&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;/code&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If the package is already installed in your system it shows that requirements are satisfied and you can update the version also.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;pip uninstall&lt;/font&gt;&lt;font face="arial" size="4"&gt; followed by the package name will uninstall that package.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;pip list&lt;/font&gt;&lt;font face="arial" size="4"&gt; will tell you the number of packages in the virtual environment.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;/font&gt;&lt;font face="courier" size="4"&gt;pip show &lt;/font&gt;&lt;font face="arial" size="4"&gt;followed by the package name will tell you the features of the package.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;pip show Django&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;Name: Django&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;Version: 3.0.6&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;Home-page: https://www.djangoproject.com/&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;Author: Django Software Foundation&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;Author-email: foundation@djangoproject.com&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;License: BSD&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;Location: c:\users\balus\envs\django\lib\site-packages&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;Requires: sqlparse, pytz, asgiref&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;Required-by: django-urls&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;pip has many more options you can go through installing pip and get more info. You can also create a package.&lt;/div&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/7976033038231283339/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/virtual-environment-and-packages.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/7976033038231283339" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/7976033038231283339" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/virtual-environment-and-packages.html" rel="alternate" title="Virtual environment and Packages - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRfJOj6hAn39SCYAUA5IPdnFWpTIUUM-F2FhvqqZQMCVJEqeQP20bfRFiHUOA8ieGwUTjFZC1h-DUgVc-itR_-Ug7FdOSw6YqLZfZnK9wVdZ4OhkiOEdSxWZ_yDsb0hAYaZkkSBdtvd_A/s72-w640-h218-c/Screenshot+%252854%2529.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-8309160300879158292</id><published>2020-05-28T10:26:00.002+05:30</published><updated>2020-05-29T17:21:28.636+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Generator"/><category scheme="http://www.blogger.com/atom/ns#" term="Iterator"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Iterators and Generators in python - Letsprogram</title><content type="html">&lt;h2 style="text-align: left;"&gt;&lt;font color="black"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;Iterators&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/h2&gt;&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;When we talk about iteration we may remember like i++ where i value iterates under a condition or &lt;a href="https://pythonbegginer.blogspot.com/2020/05/class-and-object-python.html"&gt;Objects&lt;/a&gt; can be looped over &lt;/font&gt;&lt;font face="courier" size="4"&gt;for&lt;/font&gt;&lt;font face="arial" size="4"&gt; statement.&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;nums = [1,2,3,4]&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;for num in nums:&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print(num)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;1&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;2&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;3&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;4&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;iframe allowfullscreen="" class="BLOG_video_class" height="266" src="https://www.youtube.com/embed/Dyu08G2l71c" width="320" youtube-src-id="Dyu08G2l71c"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The &lt;/font&gt;&lt;font face="courier" size="4"&gt;for&lt;/font&gt;&lt;font face="arial" size="4"&gt; loop just acts as an iterator. But there is another way we can use it is &lt;/font&gt;&lt;font face="courier" size="4"&gt;iter &lt;/font&gt;&lt;font face="arial" size="4"&gt;method&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;it = iter(nums)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;print(it)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;b style="font-family: courier; font-size: large;"&gt;&amp;lt;list_iterator object at 0x000001DBB1A70190&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;print(it.__next__())&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;1&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;print(it.__next__())&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;2&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When you look at the above code by using the &lt;/font&gt;&lt;font face="courier" size="4"&gt;__next__() &lt;/font&gt;&lt;font face="arial" size="4"&gt;method for iterator object it is printing the value in the nums list. Again after using this method, it is printing the next value in the list, not the first one it is like it holds the previous value or index of the list. You can iterate by also using the next method.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;print(next(it))&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;3&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;This style of access is clear, concise, and convenient.  The use of iterators pervades and unifies Python.  Behind the scenes, the &lt;code class="xref std std-keyword docutils literal notranslate"&gt;for&lt;/code&gt; statement calls &lt;code class="xref py py-func docutils literal notranslate"&gt;iter()&lt;/code&gt; on the container object.  The function returns an iterator object that defines the method &lt;code class="xref py py-meth docutils literal notranslate"&gt;__next__()&lt;/code&gt; which accesses elements in the container one at a time.  When there are no more elements, &lt;code class="xref py py-meth docutils literal notranslate"&gt;__next__()&lt;/code&gt; raises a &lt;code class="xref py py-exc docutils literal notranslate"&gt;StopIteration&lt;/code&gt; exception which tells the &lt;code class="xref std std-keyword docutils literal notranslate"&gt;for&lt;/code&gt; loop to terminate.&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;next(it)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;4&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;next(it)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;Traceback (most recent call last):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; File "&amp;lt;pyshell#7&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; next(it)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;StopIteration&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: arial;"&gt;See the mechanism of iterators with an example by a&amp;nbsp; class&lt;/div&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/24582bd8c0f486ee8b9f335aaef7f5c3.js"&gt;&lt;/script&gt;&lt;/font&gt;&lt;h2 style="text-align: left;"&gt;&lt;font color="black"&gt;&lt;b&gt;&lt;font face="arial" size="6"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/font&gt;&lt;/h2&gt;&lt;h2 style="text-align: left;"&gt;&lt;font color="black"&gt;&lt;b&gt;&lt;font face="arial" size="6"&gt;
Generators&lt;/font&gt;&lt;/b&gt;&lt;/font&gt;&lt;/h2&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;iframe allowfullscreen="" class="BLOG_video_class" height="266" src="https://www.youtube.com/embed/mziIj4M_uwk" width="320" youtube-src-id="mziIj4M_uwk"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;Generators are used to create iterators. These are powerful tools to build an iterator. They are just like normal &lt;a href="https://pythonbegginer.blogspot.com/2020/05/functions-in-python.html"&gt;functions&lt;/a&gt; but instead of using a &lt;/font&gt;&lt;font face="courier" size="4"&gt;return &lt;/font&gt;&lt;font face="arial" size="4"&gt;statement here, the &lt;/font&gt;&lt;font face="courier" size="4"&gt;yield&lt;/font&gt;&lt;font face="arial" size="4"&gt; is used whenever it returns a value.&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;Each time &lt;/font&gt;&lt;font face="courier" size="4"&gt;next() &lt;/font&gt;&lt;font face="arial" size="4"&gt;is called on it. Generator remembers the last value executed and resumes where it left off.&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; def reverse(data):&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for index in range(len(data)-1,-1,-1):&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yield data[index]&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; for char in reverse('golf'):&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(char)&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;f&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;l&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;o&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;g&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;Anything that can be done by using generators can also be done by using iterators in class. In the above program in iterators, we had to define the&lt;/font&gt;&lt;font face="courier" size="4"&gt; __iter__() &lt;/font&gt;&lt;font face="arial" size="4"&gt;and &lt;/font&gt;&lt;font face="courier" size="4"&gt;__next__()&lt;/font&gt;&lt;font face="arial" size="4"&gt; method but in generators, there is no need to define them. When generators terminate they also raise &lt;/font&gt;&lt;font face="courier" size="4"&gt;StopIteration&lt;/font&gt;&lt;font face="arial" size="4"&gt; and they save program states these features make&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font color="black" face="arial" size="4"&gt;it easy to create iterators with no more effort than writing a regular function.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;Some simple generators can be coded succinctly as expressions using a syntax similar to list comprehensions but with parentheses instead of square brackets. These expressions are designed for situations where the generator is used right away by an enclosing function.  Generator expressions are more compact but less versatile than full generator definitions and tend to be more memory friendly than equivalent list comprehensions.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;generator expressions&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;script src="https://gist.github.com/signatureratings/ca3331c03556ec18bc2053df0f649c16.js"&gt;&lt;/script&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/8309160300879158292/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/iterators-and-generators-in-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/8309160300879158292" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/8309160300879158292" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/iterators-and-generators-in-python.html" rel="alternate" title="Iterators and Generators in python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://img.youtube.com/vi/Dyu08G2l71c/default.jpg" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-5596269997831690956</id><published>2020-05-25T10:08:00.002+05:30</published><updated>2020-05-29T09:34:15.961+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="database"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Connecting python to database - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;font face="arial" size="4"&gt;Python is used in database applications. When discussing famous databases some are MySQL, Oracle, Microsoft SQL Server and etc.&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The database is very useful to store the information so we connect the database with the programming language. In our case, it is the python to connect database with any programming language we should install a related driver given by the database company&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpVD2Quvqf712N4ZpRFMdIscvtdtu-sIVQai7CrbHY8C9JfmicJM0NVtRBDZr6H3APNUFFI4Uqk373WLCYAEhl4TicxxVVyGD_sCFxjAugDkEzoa-h8_oKMkJNBfYef0z_BooGxisnNv0/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="connecting python with database" border="0" data-original-height="506" data-original-width="1350" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpVD2Quvqf712N4ZpRFMdIscvtdtu-sIVQai7CrbHY8C9JfmicJM0NVtRBDZr6H3APNUFFI4Uqk373WLCYAEhl4TicxxVVyGD_sCFxjAugDkEzoa-h8_oKMkJNBfYef0z_BooGxisnNv0/w640-h240/database.png" title="connecting python with database" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In this case, we gonna take MySQL as our database but to connect the database to our programming language it should be in our system or the server. If you do not have any database in your system download the &lt;a href="https://dev.mysql.com/downloads/installer/" target="_blank"&gt;MySQL installer&lt;/a&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;After, installing the MySQL database in your system then install the MySQL driver. python needs the MySQL driver to access the MySQL database and it is the same in any other database case we should install related drivers to access the related database.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The driver which we should use to access the database is "MySQL connector"&amp;nbsp; to install MySQL connector use pip command in the prompt.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4" style="background-color: white;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4" style="background-color: white;"&gt;&lt;b&gt;pip install mysql-connector&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;After the command execution, the MySQL connector is downloaded and installed.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;import mysql.connector&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If this line is executed in the python interpreter then it was successfully installed.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;After importing the driver into your program then we have to connect with the database by using the method &lt;/font&gt;&lt;font face="courier" size="4"&gt;connect() &lt;/font&gt;&lt;font face="arial" size="4"&gt;from the MySQL-connecter it takes parameters like username, password, IP address and database name.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;db = mysql.connector.connect(&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;host="localhost",&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;user="python",&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;passwd="1234"&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;database="databasename")&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;To know more about the MySQL connector for python check this link:&amp;nbsp;&lt;a href="https://dev.mysql.com/doc/relnotes/connector-python/en/" target="_blank"&gt;https://dev.mysql.com/doc/relnotes/connector-python/&lt;/a&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Here are&amp;nbsp; two small programs on how to access the database with python&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
  &lt;script src="https://gist.github.com/signatureratings/9f2242fcb0c8cd842fcfe31d74939ebc.js"&gt;&lt;/script&gt;&lt;br /&gt;
  &lt;script src="https://gist.github.com/signatureratings/f62f90525e4cae085d3a096351d56d66.js"&gt;&lt;/script&gt;&lt;font face="arial" size="4"&gt; execute statement takes the SQL commands used in the respective database.&lt;/font&gt;&lt;/font&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/5596269997831690956/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/connecting-python-to-database.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/5596269997831690956" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/5596269997831690956" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/connecting-python-to-database.html" rel="alternate" title="Connecting python to database - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpVD2Quvqf712N4ZpRFMdIscvtdtu-sIVQai7CrbHY8C9JfmicJM0NVtRBDZr6H3APNUFFI4Uqk373WLCYAEhl4TicxxVVyGD_sCFxjAugDkEzoa-h8_oKMkJNBfYef0z_BooGxisnNv0/s72-w640-h240-c/database.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-5994133592513130678</id><published>2020-05-23T10:27:00.004+05:30</published><updated>2020-05-29T09:34:30.645+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><category scheme="http://www.blogger.com/atom/ns#" term="Lambda"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Lambda functions in python - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;font face="arial" size="4"&gt;We have built-in functions in python and we can create a user-defined function as well by using the keyword def and the function name. We use the function names because it is easy to call the function again. What if we never give the function a name?&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;It becomes anonymous this function is called anonymous function or lambda. Anonymous functions are created when the function is very small like one expression. These anonymous functions are created by using the keyword called lambda.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-9EUS6ACmcpVPKPU9C_RssoNBAylYsl8lhlGGGRAd1ubO6Isc9zt1O_XU6gZRCeDKt6kGddZvi46XGq80WxlpUogDrJwb3-EDARXxu8czxPVF9FEqaFjroxIGtBlmhPQeZ1bxyqPWBTg/" style="margin-left: 1em; margin-right: 1em; text-align: center;"&gt;&lt;img alt="Lamda function" border="0" data-original-height="260" data-original-width="461" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-9EUS6ACmcpVPKPU9C_RssoNBAylYsl8lhlGGGRAd1ubO6Isc9zt1O_XU6gZRCeDKt6kGddZvi46XGq80WxlpUogDrJwb3-EDARXxu8czxPVF9FEqaFjroxIGtBlmhPQeZ1bxyqPWBTg/w400-h225/lambda.png" title="Lamda function" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In python, we can use a function to call another function. Because in python everything is considered an object. Lambda functions can be used wherever function objects are used.&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;Like nested function definitions, lambda functions can reference variables from the containing scope:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;def increase(n):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return lambda a:a+n&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;fun = increase(20)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;fun(10)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;30&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;fun(0)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;30&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Lambda function can take multiple arguments as well&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; f = lambda a,b : a*b&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;print(f(3,2))&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;6&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The main point you should understand here is lambda is a function.&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;type(lambda x:x+1)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;lt;class function&amp;gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;p style="background-color: black; color: white; margin: 20px; padding: 20px;" title="Lambda Expression"&gt;Note: Use anonymous function when  it is required for a short amount of scope&lt;/p&gt;
&lt;font color="black"&gt; &lt;/font&gt;&lt;/div&gt;&lt;/font&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;When you defined a normal function instead of lambda function you have to allocate the space for the function name and scope will be throughout the function if it not defined in the class. When you use a lambda function instead of the normal user-defined function then you do not have to waste the memory and its scope will be small not the entire program.&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="arial" size="4"&gt;To read any python programming books check this &lt;a href="https://amzn.to/3e9auHO" target="_blank"&gt;link&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/5994133592513130678/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/lambda-functions-in-python-pythonblog.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/5994133592513130678" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/5994133592513130678" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/lambda-functions-in-python-pythonblog.html" rel="alternate" title="Lambda functions in python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-9EUS6ACmcpVPKPU9C_RssoNBAylYsl8lhlGGGRAd1ubO6Isc9zt1O_XU6gZRCeDKt6kGddZvi46XGq80WxlpUogDrJwb3-EDARXxu8czxPVF9FEqaFjroxIGtBlmhPQeZ1bxyqPWBTg/s72-w400-h225-c/lambda.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-7631859625652608734</id><published>2020-05-22T14:09:00.001+05:30</published><updated>2020-05-29T09:34:45.480+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Functions in python(def) - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;font face="arial" size="4"&gt;Before discussing functions first of all why function?&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Whenever you want to repeat multiple lines of codes many times then you have to use functions because it reduces the memory consumption, the length of the code, speed of the process.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In python defining a function is done with the keyword called &lt;/font&gt;&lt;font face="courier" size="4"&gt;def.&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;It must be followed by the function name and the parenthesized list of formal parameters. The statements that form the body of the function start at the next line and must be indented.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;Example :&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;def fib(n):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; """Print the Fibonacci series up to n """&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; a,b = 0,1&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; while a&amp;lt;n :&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(a, end="")&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a,b = b,a+b&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;This is an example of a function in python.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The first statement of the function body can optionally be a string literal; this string literal is the function’s documentation string. I&lt;/font&gt;&lt;font face="arial" size="4"&gt;t’s good practice to include docstrings in code that you write, so make a habit of it.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Defining the function will never give you the output instead you have to make a function call then the function will execute.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;fib(n)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;font face="arial"&gt;Coming from other languages, you might object that &lt;/font&gt;&lt;code class="docutils literal notranslate" style="font-family: arial;"&gt;fib&lt;/code&gt;&lt;font face="arial"&gt; is not a function but a procedure since it doesn’t return a value.  In fact, even functions without a &lt;/font&gt;&lt;code class="xref std std-keyword docutils literal notranslate" style="font-family: arial;"&gt;return&lt;/code&gt;&lt;font face="arial"&gt; statement do return a value. The value is &lt;/font&gt;&lt;font face="courier"&gt;None&lt;/font&gt;&lt;font face="arial"&gt; it is actually a built-in value. In interpreter mode, you cannot see the &lt;/font&gt;&lt;font face="courier"&gt;None &lt;/font&gt;&lt;font face="arial"&gt;value by the just function call.&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;fib(0)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;print(fib(0))&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;None&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Actually, we can give the function name to another value. This serves as a general renaming mechanism or aliasing. The value of the function name have a type that is recognized by the interpreter as a user-defined function.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; fib&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;lt;function fib at 0x000001CD6AE25430&amp;gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; f=fib&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt; f&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;lt;function fib at 0x000001CD6AE25430&amp;gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;By the above example, you may understand that even after giving function name to another value the value also has the same type.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;b style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style="font-family: arial; font-size: large;"&gt;Arguments in functions&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The argument is a value that is sent to the function when you are calling the function.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Parameters are variables that are listed when defining a function.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;You have to give the same number of arguments as listed in the function definition.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;For example, the function fib is taking only one argument but you gave it three arguments then you will get an error.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;u&gt;&lt;b&gt;Arbitrary Arguments:&lt;/b&gt;&lt;/u&gt; If you do not know how many arguments that will be passed into your function, add a&amp;nbsp;&lt;/span&gt;&lt;code class="w3-codespan" style="background-color: #f1f1f1; box-sizing: inherit; color: crimson; padding-left: 4px; padding-right: 4px;"&gt;*&lt;/code&gt;&lt;span style="background-color: white;"&gt;&amp;nbsp;before the parameter name in the function definition. By putting&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;span style="background-color: white; font-family: arial; font-size: large;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: white; font-family: arial; font-size: large;"&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="w3-codespan" style="background-color: #f1f1f1; box-sizing: inherit; color: crimson; padding-left: 4px; padding-right: 4px;"&gt;*&lt;/code&gt;&lt;code class="w3-codespan" style="background-color: #f1f1f1; box-sizing: inherit; color: crimson; padding-left: 4px; padding-right: 4px;"&gt;*&lt;/code&gt;&lt;span style="background-color: white; font-family: arial; font-size: large;"&gt;before a parameter then it can accept a dictionary into it.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; font-size: large;"&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;def function(**dic):&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; font-size: large;"&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;print("my name is",dic(name))&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; font-size: large;"&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;gt;&amp;gt;&amp;gt;function(fname="max",lname="Payne")&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; font-size: large;"&gt;&lt;font face="courier"&gt;&lt;b&gt;my name is max&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;u&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white;"&gt;&lt;b style="text-decoration-line: underline;"&gt;Keyword Arguments:&lt;/b&gt;&amp;nbsp;You can give the argument value with the key in this way the order in which you are giving the value is not important.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;def example(bool,try=4,message="Please try again!"):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; while True:&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ok=input(prompt)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ok in ('y','ye','yes',1,'True'):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return True&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ok in('no','n',0,'False'):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return False&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try=try-1&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if try&amp;lt;0:&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raise ValueError("Invalid Response")&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(message)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;You can call this function in many ways like :&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;example('no')&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;example("Python Blog",2)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;example("True",4,"Come on,only yes or no")&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;There are three possibilities to call the function example because of default arguments.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Function calls in the file are valid.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
&lt;script src="https://gist.github.com/signatureratings/c3e0153cb2f304bb66471101bb774938.js"&gt;&lt;/script&gt;&lt;/font&gt;&lt;font face="arial" size="4"&gt;
But all the function calls below are invalid.&lt;/font&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;parrot()&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;parrot(voltage=5.0,'dead')&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;parrot(110,voltage=220)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;parrot(actor="IronMan")&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/7631859625652608734/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/functions-in-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/7631859625652608734" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/7631859625652608734" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/functions-in-python.html" rel="alternate" title="Functions in python(def) - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-9015747597721706316</id><published>2020-05-20T21:35:00.004+05:30</published><updated>2020-05-29T09:32:51.568+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="exceptions"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">User-defined Exceptions in python - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;Prerequisite&lt;/b&gt; - This post is an extension for the &lt;a href="https://pythonbegginer.blogspot.com/2020/05/error-handling-in-python.html"&gt;exception handling&lt;/a&gt;.&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In python, all exceptions must be instances of any &lt;a href="https://pythonbegginer.blogspot.com/2020/05/class-and-object-python.html"&gt;class&lt;/a&gt; that derives from the &lt;/font&gt;&lt;font face="courier" size="4"&gt;BaseException&lt;/font&gt;&lt;font face="arial" size="4"&gt;.&lt;/font&gt;&lt;font face="arial" size="4"&gt;Two exception classes that are not related via subclassing are never equivalent, even if they have the same name.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The Built-in exceptions can be subclassed to define new exceptions. To define User-defined exceptions it can be done by inheriting the Exception class or one of its subclass.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNMgH5fXlNLC9BNYfv5F0ZFQfvFl2pCTaoLQSvftI6EyHH-DllltdwAh38rWRDIN3CR85X2sd1-0PfKr4rPuuedFnsndGrGnbBO-ntftEztvDx7F2Iagn6amte2RjbkxI6jSvoF7SGSAQ/" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="User-defined exceptions" border="0" data-original-height="458" data-original-width="1050" height="280" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNMgH5fXlNLC9BNYfv5F0ZFQfvFl2pCTaoLQSvftI6EyHH-DllltdwAh38rWRDIN3CR85X2sd1-0PfKr4rPuuedFnsndGrGnbBO-ntftEztvDx7F2Iagn6amte2RjbkxI6jSvoF7SGSAQ/w640-h280/userdefined.png" title="User-defined exceptions" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When you try to create a new module we create many functions and classes in it. A user may not know all about it, to alert the user when there is an exception but Built-in exceptions are not suitable then user-defined functions have to be created.&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;When creating a module that can raise several distinct errors, a common practice is to create a base class for exceptions defined by that module, and subclass that to create specific exception classes for different error conditions:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;
&lt;script src="https://gist.github.com/signatureratings/06ecf5a6b51d63bddc6c11a04dc3f2c2.js"&gt;&lt;/script&gt;  
&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;
  &lt;div class="alert-message success"&gt;
&lt;i class="fa fa-check-circle"&gt;&lt;/i&gt; Exception occurred : Not Allowed&lt;/div&gt;
 &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Here class &lt;/font&gt;&lt;font face="courier" size="4"&gt;Error&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;is inheriting the &lt;/font&gt;&lt;font face="courier" size="4"&gt;Exception&lt;/font&gt;&lt;font face="arial" size="4"&gt; class and other classes are inheriting the &lt;/font&gt;&lt;font face="courier" size="4"&gt;Error&lt;/font&gt;&lt;font face="arial" size="4"&gt; class. This is a small practice used in python.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Standard modules will define their own exceptions to report errors that define in their own functions.&lt;/font&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;To define a user-defined exception first you may have to know about all the built-in exceptions and their hierarchy.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="courier"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="courier"&gt;&lt;b&gt;BaseExeption&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;-----SystemExit&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;-----KeyboardInterrupt&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;-----GeneratorExit&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;-----Exception&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |----StopIteration&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |----StopAsyncIteration&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |----ArithemeticError&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+---FloatingpointError&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+---OverflowError&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+---ZeroDivisionError&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |----AssertionError&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |----AttributeError&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |----BufferError&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |----EOFError&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |----ImportError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- ModuleNotFoundError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- LookupError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- IndexError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- KeyError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- MemoryError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- NameError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- UnboundLocalError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- OSError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- BlockingIOError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- ChildProcessError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- ConnectionError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- BrokenPipeError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- ConnectionAbortedError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- ConnectionRefusedError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- ConnectionResetError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- FileExistsError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- FileNotFoundError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- InterruptedError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- IsADirectoryError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- NotADirectoryError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- PermissionError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- ProcessLookupError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- TimeoutError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- ReferenceError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- RuntimeError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- NotImplementedError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- RecursionError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- SyntaxError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- IndentationError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- TabError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- SystemError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- TypeError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- ValueError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; +-- UnicodeError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- UnicodeDecodeError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- UnicodeEncodeError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- UnicodeTranslateError&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; +-- Warning&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- DeprecationWarning&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- PendingDeprecationWarning&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- RuntimeWarning&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- SyntaxWarning&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- UserWarning&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- FutureWarning&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- ImportWarning&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- UnicodeWarning&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- BytesWarning&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+-- ResourceWarning&lt;/b&gt;&lt;/div&gt;&lt;div style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When you learn about the Built-in exceptions you can create the user-defined exceptions easily. If the exception you wanted to create is somewhat related to here you can use it to inherit in your exception class.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;class NetworkError(Warning):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; def __init__(self,arg):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.args=arg&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;try:&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; raise NetworkError("No Internet")&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;&lt;b&gt;except NetworkError as e:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; print(e.args)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;&lt;font face="arial"&gt;&lt;b&gt;Output :&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: courier; font-size: large;"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;
  &lt;div class="alert-message success"&gt;
&lt;i class="fa fa-check-circle"&gt;&lt;/i&gt;('N',&amp;nbsp; 'o',&amp;nbsp; ' ',&amp;nbsp; 'I',&amp;nbsp; 'n',&amp;nbsp; 't',&amp;nbsp; 'e',&amp;nbsp; 'r',&amp;nbsp; 'n',&amp;nbsp; 'e',&amp;nbsp; 't')&lt;/div&gt;&lt;font face="arial" size="4"&gt;
I created an exception class called &lt;/font&gt;&lt;font face="courier" size="4"&gt;NetworkError&lt;/font&gt;&lt;font face="arial" size="4"&gt; it is not a built-in function I inherited Warning class it may or may not suit here with the context but you can inherit the &lt;/font&gt;&lt;font face="courier" size="4"&gt;Exception &lt;/font&gt;&lt;font face="arial" size="4"&gt;class or the class which inherit the &lt;/font&gt;&lt;font face="courier" size="4"&gt;Exception&lt;/font&gt;&lt;font face="arial" size="4"&gt; class. When your exception is related to the system the use &lt;/font&gt;&lt;font face="courier" size="4"&gt;OSError&lt;/font&gt;&lt;font face="arial" size="4"&gt; exception class.
&lt;/font&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/9015747597721706316/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/user-defined-exceptions-in-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/9015747597721706316" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/9015747597721706316" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/user-defined-exceptions-in-python.html" rel="alternate" title="User-defined Exceptions in python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNMgH5fXlNLC9BNYfv5F0ZFQfvFl2pCTaoLQSvftI6EyHH-DllltdwAh38rWRDIN3CR85X2sd1-0PfKr4rPuuedFnsndGrGnbBO-ntftEztvDx7F2Iagn6amte2RjbkxI6jSvoF7SGSAQ/s72-w640-h280-c/userdefined.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-3754428743759180516</id><published>2020-05-19T12:22:00.003+05:30</published><updated>2020-05-29T09:32:29.543+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Inheritance"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Multiple Inheritance in Python - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;br /&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Python supports a form of multiple inheritance as well. When a derived class has two or more parent class then it is exhibiting multiple inheritance. The syntax for multiple inheritance is :&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;class DerivedClass(base1,base2,base3):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;statement 1&amp;gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;statement n&amp;gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Python searches for attributes inherited from the parent class as left-right not searching in the same class twice.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Learn more about &lt;a href="https://pythonbegginer.blogspot.com/2020/05/inheritance-in-python.html"&gt;inheritance&amp;nbsp;&lt;/a&gt;.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In multiple inheritance there in some cases it may exhibit diamond relationships where at least one of the parent class is accessed through multiple ways from the bottom-most class.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Let's take an example where a diamond relationship exists.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAFvmAss5Xt3TXGnUdMx2fxzEvU06VFD79xiDRpOSKfIMoe74RwFglcned8GgYHBIDPy4QRuYiF1eIS2RK5btkK4s3l4sXyOJm2l-sOPqWwBWPcMLNRCKDQhd3dSrNEBgIm9v90amZyQQ/" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Diamond relationship in multiple inheritance" border="0" data-original-height="648" data-original-width="1152" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAFvmAss5Xt3TXGnUdMx2fxzEvU06VFD79xiDRpOSKfIMoe74RwFglcned8GgYHBIDPy4QRuYiF1eIS2RK5btkK4s3l4sXyOJm2l-sOPqWwBWPcMLNRCKDQhd3dSrNEBgIm9v90amZyQQ/w640-h360/MultipleInheritance.png" title="Diamond relationship in multiple inheritance" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;suppose there is a method name add in the class "Base1". Base2 and Base 3 class inherit from Base1 class if there is an overridden method add in the Base2 and Base3 then ambiguity arises which of the method add should we inherit into the class "Derived".&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
&lt;script src="//onlinegdb.com/embed/js/r1uftxZjL?theme=dark"&gt;&lt;/script&gt;
&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
&lt;script src="//onlinegdb.com/embed/js/S1wCcgZsI?theme=dark"&gt;&lt;/script&gt;
&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If the "Base2" class has no method add then it will check in Base3 class whether it has add method or not.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When every class defines the same method as having the same number of arguments than to use the base class method use the class name to access the method.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
&lt;script src="//onlinegdb.com/embed/js/SJsShx-jI?theme=dark"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src="//onlinegdb.com/embed/js/HJm2pl-iU?theme=dark"&gt;&lt;/script&gt;
&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;The output of the above code has one problem associated with it, the method m of Class1 is called twice. Python provides a solution to the above problem with the help of the&amp;nbsp;&lt;/span&gt;&lt;code style="background-color: white; border: 0px; color: rgba(0, 0, 0, 0.84); line-height: 2; margin: 0px; padding: 0px; vertical-align: baseline;"&gt;super()&lt;/code&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&amp;nbsp;function.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;script src="//onlinegdb.com/embed/js/ByvORgZj8?theme=dark"&gt;&lt;/script&gt;
&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: rgba(0, 0, 0, 0.84);"&gt;The super function will come to a conclusion about which method to execute by an order.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/3754428743759180516/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/multiple-inheritance-in-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/3754428743759180516" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/3754428743759180516" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/multiple-inheritance-in-python.html" rel="alternate" title="Multiple Inheritance in Python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAFvmAss5Xt3TXGnUdMx2fxzEvU06VFD79xiDRpOSKfIMoe74RwFglcned8GgYHBIDPy4QRuYiF1eIS2RK5btkK4s3l4sXyOJm2l-sOPqWwBWPcMLNRCKDQhd3dSrNEBgIm9v90amZyQQ/s72-w640-h360-c/MultipleInheritance.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-6015829703430300489</id><published>2020-05-17T19:01:00.003+05:30</published><updated>2020-05-29T09:33:36.754+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="class"/><category scheme="http://www.blogger.com/atom/ns#" term="Inheritance"/><category scheme="http://www.blogger.com/atom/ns#" term="Strings"/><title type="text">Inheritance in Python - Letsprogram</title><content type="html">&lt;font color="black"&gt;
&lt;br /&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Inheritance is the process of getting the features from a base class to the derived class.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;when you are defining the derived class make sure the base class name is in the scope.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;class DerivedClass(modname.BaseClass):&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;Statement 1&amp;gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;Statement n&amp;gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;When the base class you want to inherit is in another module you use its module name to use.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcP-R28Ppf2JF4FQ2pT_n1zoUcidMBI1JKfBFNKDdMEOEM7fGChjL1dKW53d02GGMrEbl_EMCz6_-t6qAMfnCYmXFnGnoDkKfqYP5yYFGN63Jr89OheZZv4I-NOdtIfv3So2DVeHiXel8/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Inheritance in Python" border="0" data-original-height="648" data-original-width="1152" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcP-R28Ppf2JF4FQ2pT_n1zoUcidMBI1JKfBFNKDdMEOEM7fGChjL1dKW53d02GGMrEbl_EMCz6_-t6qAMfnCYmXFnGnoDkKfqYP5yYFGN63Jr89OheZZv4I-NOdtIfv3So2DVeHiXel8/w640-h360/Inheritance.png" title="Inheritance in Python" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font face="arial"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;When an object is created for the derived class and looking for an attribute first python looks into the &lt;/font&gt;&lt;font face="courier"&gt;&lt;b&gt;DerivedClass &lt;/b&gt;&lt;/font&gt;&lt;font face="arial"&gt;and then into the &lt;/font&gt;&lt;font face="courier"&gt;&lt;b&gt;BaseClass.&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="courier"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Derived classes may override methods of their base classes.  Because methods have no special privileges when calling other methods of the same object, a method of a base class that calls another method defined in the same base class may end up calling a method of a derived class that overrides it.  (For C++ programmers: all methods in Python are effectively &lt;code class="docutils literal notranslate"&gt;virtual&lt;/code&gt;.)&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;An overriding method in a derived class may, in fact, want to extend rather than simply replace the base class method of the same name. There is a simple way to call the base class method directly&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;just call:&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;b style="font-family: courier; font-size: large;"&gt;BaseClass.method(self, arguments)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style="font-family: courier; font-size: large;"&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;Python has two built-in functions that work with inheritance :&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;1) &lt;/span&gt;&lt;span style="font-size: large;"&gt;&lt;font face="courier"&gt;isinstance( )&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;This method is used to check an instance type: suppose &lt;/font&gt;&lt;font face="courier" size="4"&gt;isinstance(obj,int)&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;It returns true if &lt;/font&gt;&lt;font face="courier" size="4"&gt;obj&lt;/font&gt;&lt;font face="arial" size="4"&gt; is the object of the class &lt;/font&gt;&lt;font face="courier" size="4"&gt;int&lt;/font&gt;&lt;font face="arial" size="4"&gt; or &lt;/font&gt;&lt;font face="courier" size="4"&gt;obj.__class__&lt;/font&gt;&lt;font face="arial" size="4"&gt; is &lt;/font&gt;&lt;font face="courier" size="4"&gt;int.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;2)&lt;/span&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp;issubclass( )&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;This method is used to check the class inheritance: suppose&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;/font&gt;&lt;font face="courier" size="4"&gt;issubclass(bool, int).&amp;nbsp;&lt;/font&gt;&lt;span style="font-family: arial; font-size: large;"&gt;It returns true if &lt;/span&gt;&lt;span style="font-size: large;"&gt;&lt;font face="courier"&gt;bool&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-size: large;"&gt; is a subclass of&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: large;"&gt;&lt;font face="courier"&gt;int&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: arial; font-size: large;"&gt;. Which is true.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: arial; font-size: large;"&gt;Python also supports multiple inheritances. Which means it has two or more base classes&lt;/span&gt;&lt;font face="arial" size="4"&gt;. you can think of the search for attributes inherited from a parent class as depth-first, left-to-right, not searching twice in the same class where there is an overlap in the hierarchy.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In a class hierarchy with single inheritance, &lt;em&gt;super&lt;/em&gt; can be used to refer to parent classes without naming them explicitly, thus making the code more maintainable.  This use closely parallels the use of &lt;em&gt;super&lt;/em&gt; in other programming languages.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The second use case is to support cooperative multiple inheritances in a dynamic execution environment.  This use case is unique to Python and is not found in statically compiled languages or languages that only support single inheritance.  This makes it possible to implement “diamond diagrams” where multiple base classes implement the same method.  Good design dictates that this method has the same calling signature in every case.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Dynamic ordering is necessary because all cases of multiple inheritances provide one or more diamond relationships.&amp;nbsp;&lt;/font&gt;&lt;span style="font-family: arial; font-size: large;"&gt;To keep the base classes from being accessed more than once, the dynamic algorithm linearizes the search order in a way that preserves the left-to-right ordering specified in each class, that calls each parent only once, and that is monotonic.&lt;/span&gt;&lt;/div&gt;&lt;/font&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/6015829703430300489/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/inheritance-in-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6015829703430300489" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6015829703430300489" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/inheritance-in-python.html" rel="alternate" title="Inheritance in Python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcP-R28Ppf2JF4FQ2pT_n1zoUcidMBI1JKfBFNKDdMEOEM7fGChjL1dKW53d02GGMrEbl_EMCz6_-t6qAMfnCYmXFnGnoDkKfqYP5yYFGN63Jr89OheZZv4I-NOdtIfv3So2DVeHiXel8/s72-w640-h360-c/Inheritance.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-5400564316729764910</id><published>2020-05-17T11:00:00.007+05:30</published><updated>2020-05-29T09:31:53.360+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="class"/><category scheme="http://www.blogger.com/atom/ns#" term="object"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Python Class and Object - Letsprogram</title><content type="html">&lt;font color="black"&gt;

&lt;font face="arial" size="4"&gt;Python is an Objective Oriented Programming i.e; it follows objective oriented principles. Class is one of the principles of objective programming.&amp;nbsp;&lt;/font&gt;&lt;span style="font-family: arial; font-size: large;"&gt;Almost everything in python is an Object.&lt;/span&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;A Class bundles both data and functions together.&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;Each class instance can have attributes attached to it for maintaining its state.  Class instances can also have methods (defined by its class) for modifying its state.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Python Class follows inheritance and multiple base classes. A derived class can override base class methods. And a method can call the base class method with the same name.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Class is a blueprint for an object. Class never occupies memory in the system, the memory is occupied by the object. An object follows the rules defined in the class.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;We can do aliasing in python which is multiple names (in multiple scopes) that can be bound to a single object.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEippD1j_bPWF1iir6n4SZY8YvqBf7Vq91t8MyRoTkwXjGv-srIkn_jPa3U7_toSQiAT1RLp4iDRa4XgL44PJ7Qx1jFQtFz73uxJx6MB7BWUvbLNzD7g-xPtnKnk0MMT6bY8WjxWy9GLph0/" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Class and object relation" border="0" data-original-height="648" data-original-width="1152" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEippD1j_bPWF1iir6n4SZY8YvqBf7Vq91t8MyRoTkwXjGv-srIkn_jPa3U7_toSQiAT1RLp4iDRa4XgL44PJ7Qx1jFQtFz73uxJx6MB7BWUvbLNzD7g-xPtnKnk0MMT6bY8WjxWy9GLph0/w640-h360/class.png" title="Class and object relation" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;SYNTAX for Class :&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;class ClassName:&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;lt;statement 1&amp;gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; .&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; .&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;lt;statement n&amp;gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In general, statements may be &lt;b style="text-decoration-line: underline;"&gt;functions or variables&lt;/b&gt;. When you create a class definition a new namespace is created where all assignments of local variables go into this new namespace. We discuss namespaces in another post.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;class object supports two kinds of operations&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;Instantiation&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;attribute references&lt;/font&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;class example:&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; """ A simple Example class """&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; i=2020&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; def f(self):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return "Hello"&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; def __init__(self,a,b):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;self.a = a&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;self.b = b&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;consider the above class, then &lt;/font&gt;&lt;font face="courier"&gt;&lt;b&gt;example.i&lt;/b&gt;&lt;/font&gt;&lt;font face="arial"&gt;, example.f are valid attribute references&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;Class attributes can also be assigned so that you can change the value of I from the class example.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;class instantiation uses the function notation if any parameters are required you can give it.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;font face="arial"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;x = example(20,30)&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;font face="courier"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;You are giving the class object to the local variable &lt;/font&gt;&lt;font face="courier" size="4"&gt;x&lt;/font&gt;&lt;font face="arial" size="4"&gt;. Here, it takes parameters because of the constructor.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;when a class defines an &lt;/font&gt;&lt;font face="courier" size="4"&gt;__init__() &lt;/font&gt;&lt;font face="arial" size="4"&gt;method, class instantiation invokes this method automatically for newly created class instances. &lt;/font&gt;&lt;font face="courier" size="4"&gt;__init__( ) &lt;/font&gt;&lt;font face="arial" size="4"&gt;method may take arguments for better operations in that case class instantiation takes the arguments and give to the &lt;/font&gt;&lt;font face="courier" size="4"&gt;__init__( )&lt;/font&gt;&lt;font face="arial" size="4"&gt; method.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;We discussed earlier that almost everything in python is an object to know the type of the object use &lt;/font&gt;&lt;font face="courier" size="4"&gt;type(object)&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt; or &lt;/font&gt;&lt;font face="courier" size="4"&gt;object.__class__&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;-----&amp;gt; methods from the same class call the other methods in the class by using &lt;/font&gt;&lt;font face="courier" size="4"&gt;self &lt;/font&gt;&lt;font face="arial" size="4"&gt;argument :&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;class book:&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; def __init__(self):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.data=[]&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; def add(x):&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.data.append(x)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; def addtwice(x)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.add(x)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.add(x)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When&amp;nbsp;&lt;/font&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;addtwice()&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font face="arial" size="4"&gt;function accessed through an object then it will call add function from the same class.&lt;/font&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;

&lt;script src="https://gist.github.com/signatureratings/87fa1e899b97e697ab8373a9bdbadd53.js"&gt;&lt;/script&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/5400564316729764910/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/class-and-object-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/5400564316729764910" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/5400564316729764910" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/class-and-object-python.html" rel="alternate" title="Python Class and Object - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEippD1j_bPWF1iir6n4SZY8YvqBf7Vq91t8MyRoTkwXjGv-srIkn_jPa3U7_toSQiAT1RLp4iDRa4XgL44PJ7Qx1jFQtFz73uxJx6MB7BWUvbLNzD7g-xPtnKnk0MMT6bY8WjxWy9GLph0/s72-w640-h360-c/class.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-9141083965176580725</id><published>2020-05-16T11:00:00.017+05:30</published><updated>2020-05-20T12:01:55.567+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="errors"/><category scheme="http://www.blogger.com/atom/ns#" term="exceptions"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Error Handling in Python</title><content type="html">&lt;font color="black"&gt;
&lt;font face="arial" size="4"&gt;There are two types of errors :&lt;/font&gt;&lt;div&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;font color="black"&gt;&lt;font face="arial" size="4"&gt;Syntax Errors&lt;/font&gt;&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: arial; font-size: large;"&gt;Exceptions&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;Syntax Errors occur due to invalid syntax in the program which can be avoided by practice and experience. But, the main problem is an exception that occurs at run-time execution even if the program is syntactically correct.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdbWg1qcLWumnGq51LFytgfyozETwf9vvUpP5V6-ESOkRrGG8Q36FbFPUVl4XBnlaM_iz4Zu30jViPJrbEvx_kNGxAv39nfCzve4qo3vsA-lnx8xb1OAHthxQFq7pJhrDfQW20lAYlCYM/" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Errors in python" border="0" data-original-height="1874" data-original-width="2499" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdbWg1qcLWumnGq51LFytgfyozETwf9vvUpP5V6-ESOkRrGG8Q36FbFPUVl4XBnlaM_iz4Zu30jViPJrbEvx_kNGxAv39nfCzve4qo3vsA-lnx8xb1OAHthxQFq7pJhrDfQW20lAYlCYM/w400-h300/romson-preechawit-Vy2cHqm0mCs-unsplash+%25281%2529.jpg" title="Errors in python" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font color="black" face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="courier" size="4"&gt;&amp;gt;&amp;gt;&amp;gt; 18*(2/0)&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;Traceback (most recent call last):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;File &lt;/span&gt;&lt;span class="nb" style="font-family: courier; font-size: large;"&gt;"&amp;lt;stdin&amp;gt;"&lt;/span&gt;&lt;span style="font-family: courier; font-size: large;"&gt;, line &lt;/span&gt;&lt;span class="m" style="font-family: courier; font-size: large;"&gt;1&lt;/span&gt;&lt;span style="font-family: courier; font-size: large;"&gt;, in &lt;/span&gt;&lt;span class="n" style="font-family: courier; font-size: large;"&gt;&amp;lt;module&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="gr" style="font-family: courier; font-size: large;"&gt;ZeroDivisionError&lt;/span&gt;&lt;span style="font-family: courier; font-size: large;"&gt;: &lt;/span&gt;&lt;span class="n" style="font-family: courier; font-size: large;"&gt;division by zero&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="n" style="font-family: courier; font-size: large;"&gt;&amp;gt;&amp;gt;&amp;gt; "Pythonblog"+2020&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;Traceback (most recent call last):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: courier; font-size: large;"&gt;File &lt;/span&gt;&lt;span class="nb" style="font-family: courier; font-size: large;"&gt;"&amp;lt;stdin&amp;gt;"&lt;/span&gt;&lt;span style="font-family: courier; font-size: large;"&gt;, line &lt;/span&gt;&lt;span class="m" style="font-family: courier; font-size: large;"&gt;1&lt;/span&gt;&lt;span style="font-family: courier; font-size: large;"&gt;, in &lt;/span&gt;&lt;span class="n" style="font-family: courier; font-size: large;"&gt;&amp;lt;module&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="gr" style="font-family: courier; font-size: large;"&gt;TypeError&lt;/span&gt;&lt;span style="font-family: courier; font-size: large;"&gt;: &lt;/span&gt;&lt;span class="n" style="font-family: courier; font-size: large;"&gt;Can't convert 'int' object to str implicitly&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="n" style="font-size: large;"&gt;&lt;font face="arial"&gt;Exceptions are different types and the type in printed in the output. ZeroDivisionError,TypeError,NameError are some exception names.Those are built-in exceptions. User-defined exceptions also exist. The names of exceptions are built-in but not reserved keywords.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="n" style="font-size: large;"&gt;&lt;font face="arial"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="n" style="font-size: large;"&gt;&lt;font face="arial"&gt;When an exception occurs in the program the remaining program will stop executing it.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="n" style="font-size: large;"&gt;&lt;font face="arial"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;f = open("filename.txt","a")&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;f.write("Testing the file")&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;print("Succesfully written into a file ")&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;f.close()&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When the error occurred at first line by invalid filename then remaining lines of code will not execute further.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="n" style="font-size: large;"&gt;&lt;font face="arial"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="n"&gt;&lt;font face="arial" size="6"&gt;&lt;b&gt;How to handle the exception&lt;/b&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;When an exception occurs in the program it will terminate. To stop this we use a few keywords like try, except, raise, and finally.&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;In the above example, we add a string and a number to not takes place in that situation we have to place a condition that should be an integer.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;while True:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp; try:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x = int(input("Enter any number"))&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp; except (ValueError,RuntimeError):&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print("Sorry,Only integers are allowed")&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;First, &lt;/font&gt;&lt;font face="courier" size="4"&gt;try &lt;/font&gt;&lt;font face="arial" size="4"&gt;clause (or) block is executed after executing this clause then if an exception occurs &lt;/font&gt;&lt;font face="courier" size="4"&gt;except&lt;/font&gt;&lt;font face="arial" size="4"&gt; clause with the type matches the exception name after the &lt;/font&gt;&lt;font face="courier" size="4"&gt;except&amp;nbsp;&lt;/font&gt;&lt;font face="arial" size="4"&gt;keyword is executed by skipping the &lt;/font&gt;&lt;font face="courier" size="4"&gt;try &lt;/font&gt;&lt;font face="arial" size="4"&gt;block. If not &lt;/font&gt;&lt;font face="courier" size="4"&gt;except &lt;/font&gt;&lt;font face="arial" size="4"&gt;clause is not executed.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;try, except&lt;/font&gt;&lt;font face="arial" size="4"&gt; clause have an optional &lt;/font&gt;&lt;font face="courier" size="4"&gt;else&lt;/font&gt;&lt;font face="arial" size="4"&gt; clause which, when present will follow all &lt;/font&gt;&lt;font face="courier" size="4"&gt;except&lt;/font&gt;&lt;font face="arial" size="4"&gt; clause. when it doesn't raise any error then it will execute &lt;/font&gt;&lt;font face="courier" size="4"&gt;else&lt;/font&gt;&lt;font face="arial" size="4"&gt; clause.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;raise&lt;/font&gt;&lt;font face="arial" size="4"&gt; statement is used to force an exception to occur.&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If you don't want the exception to be handled re-raise the exception.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;gt;&amp;gt;&amp;gt;try:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;raise NameError(pythonblog)&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;except NameError as n:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print(n.args,"Not defined")&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;raise&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;"pythonblog" Not defined&lt;/font&gt;&lt;/div&gt;&lt;pre&gt;&lt;font face="courier"&gt;&lt;span class="gt"&gt;Traceback (most recent call last):&lt;/span&gt;
  File &lt;span class="nb"&gt;"&amp;lt;stdin&amp;gt;"&lt;/span&gt;, line &lt;span class="m"&gt;2&lt;/span&gt;, in &lt;span class="n"&gt;&amp;lt;module&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/font&gt;&lt;/pre&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;span class="gr"&gt;NameError&lt;/span&gt;: pythonblog&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;finally&lt;/b&gt;&lt;/font&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;finally&lt;/font&gt;&lt;font face="arial" size="4"&gt;, clause runs whether the &lt;/font&gt;&lt;font face="courier" size="4"&gt;try&lt;/font&gt;&lt;font face="arial" size="4"&gt; statement produces an exception. &lt;/font&gt;&lt;font face="courier" size="4"&gt;finally &lt;/font&gt;&lt;font face="arial" size="4"&gt;runs after executing all &lt;/font&gt;&lt;font face="courier" size="4"&gt;try&lt;/font&gt;&lt;font face="arial" size="4"&gt; blocks.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If an exception occurs while executing a &lt;/font&gt;&lt;font face="courier" size="4"&gt;try&lt;/font&gt;&lt;font face="arial" size="4"&gt; clause then an exception may be handled by the &lt;/font&gt;&lt;font face="courier" size="4"&gt;except&lt;/font&gt;&lt;font face="arial" size="4"&gt; clause if not then the exception is re-raised after executing the &lt;/font&gt;&lt;font face="courier" size="4"&gt;finally&lt;/font&gt;&lt;font face="arial" size="4"&gt; block.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;gt;&amp;gt;&amp;gt;try:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;raise KeyboardInterrupt&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;finally:&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print("Python blog")&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;Python blog&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;font face="courier" size="4"&gt;&lt;span class="nc"&gt;KeyboardInterrupt&lt;/span&gt;
&lt;span class="gt"&gt;Traceback (most recent call last):&lt;/span&gt;
  File &lt;span class="nb"&gt;"&amp;lt;stdin&amp;gt;"&lt;/span&gt;, line &lt;span class="m"&gt;2&lt;/span&gt;, in &lt;span class="n"&gt;&amp;lt;module&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;The error raised after executing the finally block.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;To know more about &lt;a href="http://pythonbegginer.blogspot.com/2020/05/user-defined-exceptions-in-python.html"&gt;user-defined exceptions&lt;/a&gt; you need to know about &lt;a color="blue" href="http://pythonbegginer.blogspot.com/2020/05/class-and-object-python.html" id="link"&gt;class&lt;/a&gt; and &lt;a color="blue" href="http://pythonbegginer.blogspot.com/2020/05/inheritance-in-python.html" id="Inheritance"&gt;inheritance&lt;/a&gt;.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;You can check the official python documentation about &lt;a href="https://docs.python.org/3/tutorial/errors.html" target="_blank"&gt;errors and exceptions&lt;/a&gt;.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="blue" face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Program: Using try and except clause to find the age greater than 18&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
&lt;script src="https://gist.github.com/signatureratings/b3c95d47748b743eb6520cc2c5cc3da4.js"&gt;&lt;/script&gt; &lt;/font&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/9141083965176580725/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/error-handling-in-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/9141083965176580725" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/9141083965176580725" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/error-handling-in-python.html" rel="alternate" title="Error Handling in Python" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdbWg1qcLWumnGq51LFytgfyozETwf9vvUpP5V6-ESOkRrGG8Q36FbFPUVl4XBnlaM_iz4Zu30jViPJrbEvx_kNGxAv39nfCzve4qo3vsA-lnx8xb1OAHthxQFq7pJhrDfQW20lAYlCYM/s72-w400-h300-c/romson-preechawit-Vy2cHqm0mCs-unsplash+%25281%2529.jpg" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-6919455445570755160</id><published>2020-05-15T11:00:00.020+05:30</published><updated>2020-05-15T11:38:09.385+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Files"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Operation on files using Python</title><content type="html">&lt;font color="black"&gt;
&lt;font color="black" face="arial" size="4"&gt;To do any operations on the files we need to open the file first. The&amp;nbsp;&lt;/font&gt;&lt;font face="courier" size="4"&gt;open()&lt;/font&gt;&lt;font color="black" face="arial" size="4"&gt; method is used to returns the file object and it takes two arguments&amp;nbsp;&lt;/font&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;div&gt;&lt;font color="black" face="courier" size="4"&gt;f = open("file_name",'mode')&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwr-_VbjnE9MUmPfm42Trfn4nm-qG4jmO3KubYtnDc7GOzyGde8zbdQi-c0X1reIiVCPKbm_TWOlbUbc_PAa2fQe7uPfo7OiVIodPb_bSYOKjFHPvpUG9QRkk-BhkmJt2YnNgX7G638ys/" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="methods to access files" border="0" data-original-height="3051" data-original-width="4589" height="266" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwr-_VbjnE9MUmPfm42Trfn4nm-qG4jmO3KubYtnDc7GOzyGde8zbdQi-c0X1reIiVCPKbm_TWOlbUbc_PAa2fQe7uPfo7OiVIodPb_bSYOKjFHPvpUG9QRkk-BhkmJt2YnNgX7G638ys/w400-h266/viktor-talashuk-05HLFQu8bFw-unsplash.jpg" title="methods to access the files" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;The first argument is a string containing the filename.  The second argument is another string containing a few characters describing the way in which the file will be used. To open the file for reading mode=" r ", opening the file for writing mode =&amp;nbsp; " w"&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;when opened in writing mode if the file already exists then it will rewrite the content, to avoid this use mode = " a " this will add the content at the end of the file.&amp;nbsp;&lt;/font&gt;&lt;font color="black" face="arial" size="4"&gt;&lt;span style="background-color: white; color: black;"&gt;The special mode 'rU' is the "Universal" option for text files where it's smart about converting different line-endings so they always come through as a simple '\n'.&lt;/span&gt;&lt;span style="background-color: white; color: black;"&gt;&amp;nbsp;The mode is optional because when the mode is omitted " r " will be taken as the mode.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="6"&gt;&lt;span style="background-color: white; color: black;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="arial" size="6"&gt;&lt;span style="background-color: white; color: black;"&gt;&lt;b&gt;Methods for File objects&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;font color="black" face="arial" size="4"&gt;&lt;span black="" style="background-color: white;"&gt;&lt;b&gt;read()&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;font color="black" size="4"&gt;&lt;font face="arial"&gt;To read file contents call&lt;/font&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&lt;font face="courier"&gt;f.read(size)&lt;/font&gt;&lt;/b&gt;&lt;font face="courier"&gt; &lt;/font&gt;&lt;/font&gt;&lt;font color="black" face="arial" size="4"&gt;which reads size data and returns string in textmode and bytes object in binary mode.&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;font color="black" face="arial" size="4"&gt;&lt;b&gt;readline()&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;It will read a single line from the file and&amp;nbsp;&lt;/font&gt;&lt;font color="black" face="arial" size="4"&gt;a newline character (&lt;code class="docutils literal notranslate"&gt;\n&lt;/code&gt;) is left at the end of the string but only for the last line, it will be not printed.&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;readlines()&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If you want to read all the lines of a file in a list you can also use &lt;code class="docutils literal notranslate"&gt;list(f) &lt;font face="arial"&gt;it will also gives you the same output.&lt;/font&gt;&lt;/code&gt;&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;&lt;code class="docutils literal notranslate"&gt;&lt;font face="arial"&gt;&lt;b&gt;write(string)&lt;/b&gt;&lt;/font&gt;&lt;/code&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;&lt;code class="docutils literal notranslate"&gt;f.write(string)&lt;/code&gt; writes the contents of &lt;em&gt;string&lt;/em&gt; to the file, returning the number of characters written.&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;To write any other types in your files you have to convert them into strings.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;tuple = ( "PythonBlog", 13 )&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="courier" size="4"&gt;&lt;b&gt;a = str(tuple)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;f.write(a)&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;tell()&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;tell function will return the position of the pointer where your object is pointed to the file&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;seek(offset, whence)&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;To change the object's position we use the seek method. To move x values forward take offset value as x.&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;It is good practice to use the &lt;code class="xref std std-keyword docutils literal notranslate"&gt;with&lt;/code&gt; keyword when dealing with file objects.  The advantage is that the file is properly closed after its suite finishes, even if an exception is raised at some point.  Using &lt;code class="xref std std-keyword docutils literal notranslate"&gt;with&lt;/code&gt; is also much shorter than writing equivalent &lt;code class="xref std std-keyword docutils literal notranslate"&gt;try&lt;/code&gt;-&lt;code class="xref std std-keyword docutils literal notranslate"&gt;finally&lt;/code&gt; blocks.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;with open("Pythonblog.txt") as f :&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; read_data = f.read()&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;If with is not used make sure&amp;nbsp;&lt;/font&gt;&lt;font face="courier" size="4"&gt; f.close()&lt;/font&gt;&lt;font face="arial" size="4"&gt; is used in the program so that the file will be closed.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font clor="black" face="arial" size="4"&gt;Python also uses JSON module to store the data.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;write a program to print the longest word in the file?&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color="black" face="arial" size="4"&gt;&lt;span style="background-color: white; color: black;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: black;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;
&lt;script src="https://gist.github.com/signatureratings/af24a1148a252d945b1211ba60228c5e.js"&gt;&lt;/script&gt;</content><link href="https://pythonbegginer.blogspot.com/feeds/6919455445570755160/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/methods-in-filehandling-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6919455445570755160" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6919455445570755160" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/methods-in-filehandling-python.html" rel="alternate" title="Operation on files using Python" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwr-_VbjnE9MUmPfm42Trfn4nm-qG4jmO3KubYtnDc7GOzyGde8zbdQi-c0X1reIiVCPKbm_TWOlbUbc_PAa2fQe7uPfo7OiVIodPb_bSYOKjFHPvpUG9QRkk-BhkmJt2YnNgX7G638ys/s72-w400-h266-c/viktor-talashuk-05HLFQu8bFw-unsplash.jpg" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-6632749560350167098</id><published>2020-05-14T15:30:00.001+05:30</published><updated>2020-05-14T21:54:02.149+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="modules"/><category scheme="http://www.blogger.com/atom/ns#" term="Strings"/><category scheme="http://www.blogger.com/atom/ns#" term="win10toast"/><title type="text">win10toast package in python</title><content type="html">&lt;font color = "black"&gt;
&lt;div&gt;&lt;font face="arial" size="4"&gt;You can use this package to handle notifications for the system&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;font face="arial" size="4"&gt;The package is available in PyPI download the package using &lt;b&gt;pip&lt;/b&gt;&amp;nbsp; command&amp;nbsp; :&lt;/font&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;pip install win10toast&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Make sure you had pip in your system to check it is available or not use the command&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier" size="4"&gt;pip -- version&lt;/font&gt;&lt;font face="arial" size="4"&gt; in the command line if it is available in your system you can proceed with the first command, If not try installing pip by this &lt;a href="https://pip.pypa.io/en/stable/installing/" target="_blank"&gt;link&lt;/a&gt;.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;After installing the win10toast package&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Import the package into your program there are many classes in this package like ToastNotifier, CreateWindow, DestroyWindow, UpdateWindow, load image ...etc&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;We use ToastNotifier class this class had 3 methods in it&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;notification_active&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;on_destroy&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font face="arial" size="4"&gt;show_toast&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;1) notification_active() :&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;b style="font-family: arial;"&gt;&amp;nbsp;SYNTAX : &lt;/b&gt;&lt;font face="courier"&gt;&lt;b&gt;ToastNotifier().notification_active()&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;&lt;font face="courier"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;This method returns whether an active notification shown in the system or not&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="line-height: 125%; margin: 0px;"&gt;1
2
3&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style="line-height: 125%; margin: 0px;"&gt;&lt;span style="color: #008800; font-weight: bold;"&gt;from&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;win10toast&lt;/span&gt; &lt;span style="color: #008800; font-weight: bold;"&gt;import&lt;/span&gt; ToastNotifier
toast &lt;span style="color: #333333;"&gt;=&lt;/span&gt; ToastNotifier()
toast&lt;span style="color: #333333;"&gt;.&lt;/span&gt;notification_active()
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;u&gt;Output:&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="courier"&gt;&lt;font size="4"&gt;Fa&lt;/font&gt;&lt;span style="font-size: large;"&gt;lse&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="arial" size="4"&gt;2) on_destroy() :&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="arial" size="4"&gt;SYNTAX : &lt;/font&gt;&lt;font face="courier" size="4"&gt;ToastNotifier().on_destroy(hwnd,msg,wparam,lparam)&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face="courier" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;This method cleans after the notification ended 4 parameters are required&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&amp;nbsp;for the on_destroy method.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;3) show_toast() :&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;SYNTAX :&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;b style="font-family: courier; font-size: large;"&gt;show_toast(title,msg,icon_path,duration,threaded)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style="font-family: courier; font-size: large;"&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="line-height: 125%; margin: 0px;"&gt;1
2
3&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style="line-height: 125%; margin: 0px;"&gt;&lt;span style="color: #008800; font-weight: bold;"&gt;from&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;win10toast&lt;/span&gt; &lt;span style="color: #008800; font-weight: bold;"&gt;import&lt;/span&gt; ToastNotifier
toast &lt;span style="color: #333333;"&gt;=&lt;/span&gt; ToastNotifier()
toast&lt;span style="color: #333333;"&gt;.&lt;/span&gt;show_toast(&lt;span style="background-color: #fff0f0;"&gt;"Instagram"&lt;/span&gt;,&lt;span style="background-color: #fff0f0;"&gt;"Follow pythonblog for more updates"&lt;/span&gt;,duration&lt;span style="color: #333333;"&gt;=&lt;/span&gt;&lt;span style="color: #0000dd; font-weight: bold;"&gt;20&lt;/span&gt;)
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="courier" size="4"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;b&gt;OUTPUT :&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;Notification will be seen in the system&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;iframe allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/BtoTNqrH63E" width="560"&gt;&lt;/iframe&gt;
</content><link href="https://pythonbegginer.blogspot.com/feeds/6632749560350167098/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/win10toast-package-in-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6632749560350167098" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6632749560350167098" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/win10toast-package-in-python.html" rel="alternate" title="win10toast package in python" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://img.youtube.com/vi/BtoTNqrH63E/default.jpg" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-6812101044647041506</id><published>2020-05-04T15:22:00.003+05:30</published><updated>2020-05-29T09:31:08.891+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="Strings"/><title type="text">String Operations in Python - Letsprogram</title><content type="html">&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: #222222; text-align: justify;"&gt;&lt;b&gt;To know basic operations with strings in python : &lt;a href="https://pythonbegginer.blogspot.com/2020/05/introduction-to-python.html"&gt;check this post&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: #222222; text-align: justify;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: #222222; text-align: justify;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIZttcAYDUWYut2x87ID3C0USOgSrusYnGUhMBVpW9GKcLIfZHoe7Z0xSr7pOJ8loXG-uoRoxoH9QeDNXKxQOjkLHKEd2FmsZPKC8t5en9BmH18Nw-QEBwJw3l4LAg6Wpnqbz9j0F3_Ss/" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="String operations in python" border="0" data-original-height="3078" data-original-width="5472" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIZttcAYDUWYut2x87ID3C0USOgSrusYnGUhMBVpW9GKcLIfZHoe7Z0xSr7pOJ8loXG-uoRoxoH9QeDNXKxQOjkLHKEd2FmsZPKC8t5en9BmH18Nw-QEBwJw3l4LAg6Wpnqbz9j0F3_Ss/w400-h225/hitesh-choudhary-D9Zow2REm8U-unsplash.jpg" title="String operations in python" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style="background-color: white; color: #222222; text-align: justify;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;span style="background-color: white; color: #222222; text-align: justify;"&gt;Strings can be concatenated (glued together) with the&amp;nbsp;&lt;/span&gt;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; color: #222222; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;+&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; color: #222222; text-align: justify;"&gt;&amp;nbsp;operator, and repeated with&amp;nbsp;&lt;/span&gt;&lt;code class="docutils literal notranslate" style="border-radius: 3px; color: #222222; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;span style="background-color: #ecf0f3;"&gt;*&lt;/span&gt;&lt;span style="background-color: white;"&gt;&amp;nbsp;.&amp;nbsp;&lt;font face="arial"&gt;You can&lt;/font&gt;&amp;nbsp;&lt;font face="arial"&gt;concatenate strings by operators like + and *&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;code class="docutils literal notranslate" style="border-radius: 3px; color: #222222; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;span style="background-color: white;"&gt;&lt;font face="arial"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;code class="docutils literal notranslate" style="border-radius: 3px; color: #222222; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;span style="background-color: white;"&gt;&lt;font face="arial"&gt;Strings can be indexed with subscript starts from 0.&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face="arial" size="4"&gt;&lt;code class="docutils literal notranslate" style="border-radius: 3px; color: #222222; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;span style="background-color: white;"&gt;&lt;font face="arial"&gt;Example :&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/font&gt;&lt;i style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;var&lt;/i&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;[0],&lt;/span&gt;&lt;i style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;var&lt;/i&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;[1]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;if ,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;i style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;var =&amp;nbsp;&lt;/i&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;"Python Blog" then&amp;nbsp;&lt;/span&gt;&lt;i style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;var&lt;/i&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;[0] = P ,&amp;nbsp;&lt;/span&gt;&lt;i style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;var&lt;/i&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;[10] = g&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;p style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot;, arial, sans-serif; font-size: 16px; line-height: 22.4px; text-align: justify;"&gt;Note that since -0 is the same as 0, negative indices start from -1.&lt;/p&gt;&lt;p style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot;, arial, sans-serif; font-size: 16px; line-height: 22.4px; text-align: justify;"&gt;In addition to indexing,&amp;nbsp;&lt;em&gt;slicing&lt;/em&gt;&amp;nbsp;is also supported. While indexing is used to obtain individual characters,&amp;nbsp;&lt;em&gt;slicing&lt;/em&gt;&amp;nbsp;allows you to obtain substring.&lt;/p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;Note how the start is always included, and the end always excluded. This makes sure that&amp;nbsp;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; font-family: monospace, sans-serif; font-size: 15.44px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;s[:i]&lt;/span&gt;&amp;nbsp;&lt;span class="pre" style="hyphens: none;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span class="pre" style="hyphens: none;"&gt;s[i:]&lt;/span&gt;&lt;/code&gt;&amp;nbsp;is always equal to&amp;nbsp;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; font-family: monospace, sans-serif; font-size: 15.44px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;s&lt;/span&gt;&lt;/code&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; font-family: monospace, sans-serif; font-size: 15.44px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;Slice indices have useful defaults; an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;For non-negative indices, the length of a slice is the difference of the indices, if both are within bounds. For example, the length of&amp;nbsp;&lt;/span&gt;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; color: #222222; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;word[1:3]&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;is 2.&lt;/span&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;Attempting to use an index that is too large will result in an error.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src="https://gist.github.com/signatureratings/936f2a1c855480b9b5c838e231d81836.js"&gt;&lt;/script&gt;
&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;&lt;font size="4" style="color: black; font-family: &amp;quot;times new roman&amp;quot;; text-align: left;"&gt;&lt;code class="docutils literal notranslate" style="border-radius: 3px; color: #222222; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;span style="background-color: white;"&gt;&lt;font face="arial" style="font-family: arial;"&gt;Suppose a Variable&amp;nbsp;&lt;/font&gt;&lt;font face="georgia"&gt;&lt;i&gt;var&lt;/i&gt;&lt;/font&gt;&lt;font face="arial" style="font-family: arial;"&gt;&amp;nbsp;is holding a string in python we can apply operations on var so that it can be concatenated but you cannot the value of&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/font&gt;&lt;i style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;var&lt;/i&gt;&lt;font size="4" style="color: black; font-family: &amp;quot;times new roman&amp;quot;; text-align: left;"&gt;&lt;code class="docutils literal notranslate" style="border-radius: 3px; color: #222222; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;span style="background-color: white;"&gt;&lt;font face="arial" style="font-family: arial;"&gt;&amp;nbsp;once you had declared to it.This is know as immutable. Strings are immutable in nature so,that we cannot slice a variable like&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/font&gt;&lt;i style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;var.&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;&lt;i style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;&lt;i style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;&lt;div style="color: black; font-family: &amp;quot;times new roman&amp;quot;; font-size: medium; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;But we all know that python is famous for modules and packages. Everything in python is considered as an object, Python gives you predefined functions for strings to do some operations&lt;/font&gt;&lt;/div&gt;&lt;div style="color: black; font-family: &amp;quot;times new roman&amp;quot;; font-size: medium; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="color: black; font-family: &amp;quot;times new roman&amp;quot;; font-size: medium; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;NOTE: Object has properties of a class or predefined datatype. That is class has functions in it so that objects can access those functions.&lt;/font&gt;&lt;/div&gt;&lt;div style="color: black; font-family: &amp;quot;times new roman&amp;quot;; font-size: medium; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="color: black; font-family: georgia; font-size: large; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;span style="color: #222222;"&gt;There is also no mutable string type, but&amp;nbsp;&lt;/span&gt;&lt;code class="xref py py-meth docutils literal notranslate" style="background-color: transparent; border-radius: 3px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;str.join()&lt;/span&gt;&lt;/code&gt;&lt;span style="color: #222222;"&gt;&amp;nbsp;or&amp;nbsp;&lt;/span&gt;&lt;code class="xref py py-class docutils literal notranslate" style="background-color: transparent; border-radius: 3px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;io.StringIO&lt;/span&gt;&lt;/code&gt;&lt;span style="color: #222222;"&gt;&amp;nbsp;can be used to efficiently construct strings from multiple fragments.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="color: black; font-family: georgia; font-size: large; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;span style="color: #222222;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="color: black; font-family: georgia; font-size: large; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;span style="color: #222222;"&gt;Strings may also be created from other objects using the&amp;nbsp;&lt;/span&gt;&lt;a class="reference internal" href="https://docs.python.org/3/library/stdtypes.html#str" style="color: #6363bb; text-decoration-line: none;" title="str"&gt;&lt;code class="xref py py-class docutils literal notranslate" style="background-color: transparent; border-radius: 3px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;str&lt;/span&gt;&lt;/code&gt;&lt;/a&gt;&lt;span style="color: #222222;"&gt;&amp;nbsp;constructor. Like&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="color: black; font-family: georgia; font-size: large; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;span style="color: #222222;"&gt;var = str("Python Blog") give you the string.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="color: black; font-family: georgia; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;span style="color: #222222;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="color: black; font-style: normal; text-align: justify;"&gt;&lt;dt style="color: #222222; font-family: &amp;quot;lucida grande&amp;quot;, arial, sans-serif; font-size: 16px; text-align: start;"&gt;&lt;font size="4"&gt;&lt;em class="property" style="font-family: &amp;quot;lucida grande&amp;quot;, arial, sans-serif;"&gt;class&amp;nbsp;&lt;/em&gt;&lt;code class="sig-name descname" style="background-color: transparent; border-radius: 3px; font-family: monospace, sans-serif; font-size: 19.2px; font-weight: bold; padding: 0px 1px;"&gt;str&lt;/code&gt;&lt;span class="sig-paren" style="font-family: &amp;quot;lucida grande&amp;quot;, arial, sans-serif; font-size: larger;"&gt;(&lt;/span&gt;&lt;em class="sig-param" style="font-family: monospace, sans-serif;"&gt;object=b''&lt;/em&gt;&lt;font face="lucida grande, arial, sans-serif"&gt;,&amp;nbsp;&lt;/font&gt;&lt;em class="sig-param" style="font-family: monospace, sans-serif;"&gt;encoding='utf-8'&lt;/em&gt;&lt;font face="lucida grande, arial, sans-serif"&gt;,&amp;nbsp;&lt;/font&gt;&lt;em class="sig-param" style="font-family: monospace, sans-serif;"&gt;errors='strict'&lt;/em&gt;&lt;span class="sig-paren" style="font-size: larger;"&gt;&lt;font face="lucida grande, arial, sans-serif"&gt;) returns the String object. &lt;/font&gt;&lt;font face="courier"&gt;str&lt;/font&gt;&lt;font face="lucida grande, arial, sans-serif"&gt; takes an object, encoding, and errors as inputs. encoding and errors are optional,&lt;/font&gt;&lt;/span&gt;&lt;font face="arial"&gt;&lt;em class="property" style="text-align: start;"&gt;class&amp;nbsp;&lt;/em&gt;&lt;code class="sig-name descname" style="border-radius: 3px; font-weight: bold; padding: 0px 1px; text-align: start;"&gt;str&lt;/code&gt;&lt;span class="sig-paren" style="text-align: start;"&gt;(&lt;/span&gt;&lt;em class="sig-param" style="text-align: start;"&gt;object=''&lt;/em&gt;&lt;span class="sig-paren" style="text-align: start;"&gt;)&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/dt&gt;&lt;dt style="color: #222222; font-family: &amp;quot;lucida grande&amp;quot;, arial, sans-serif; font-size: 16px; text-align: start;"&gt;&lt;font size="4"&gt;&lt;font face="lucida grande, arial, sans-serif"&gt;If they are not given the values then &lt;/font&gt;&lt;font face="courier"&gt;str(object)&lt;/font&gt;&lt;font face="lucida grande, arial, sans-serif"&gt; returns &lt;/font&gt;&lt;font face="courier"&gt;object.__str__()&lt;/font&gt;&lt;font face="lucida grande, arial, sans-serif"&gt;&amp;nbsp;which is informal way to print the string.&lt;/font&gt;&lt;/font&gt;&lt;/dt&gt;&lt;dt style="color: #222222; font-family: &amp;quot;lucida grande&amp;quot;, arial, sans-serif; font-size: 16px; text-align: start;"&gt;&lt;span style="font-size: larger;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/dt&gt;&lt;dt style="color: #222222; font-family: &amp;quot;lucida grande&amp;quot;, arial, sans-serif; font-size: large; text-align: start;"&gt;&lt;span class="sig-paren" style="font-size: larger;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dt style="color: #222222; font-family: &amp;quot;lucida grande&amp;quot;, arial, sans-serif; font-size: large; text-align: start;"&gt;&lt;span class="sig-paren" style="font-size: larger;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd style="color: #222222; font-family: &amp;quot;lucida grande&amp;quot;, arial, sans-serif; font-size: 16px; line-height: 20.8px; margin-bottom: 10px; margin-left: 30px; margin-top: 3px;"&gt;&lt;/dd&gt;&lt;/div&gt;&lt;div style="color: black; font-family: &amp;quot;times new roman&amp;quot;; font-size: medium; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="color: black; font-family: &amp;quot;times new roman&amp;quot;; font-size: medium; font-style: normal; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: arial; font-size: large; text-align: justify;"&gt;&lt;i style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;&lt;font face="arial" size="4"&gt;&lt;div class="highlight-python3 notranslate" style="position: relative; text-align: start;"&gt;&lt;div class="highlight" style="background: rgb(238, 255, 204);"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: white; color: #222222; font-family: georgia; font-size: large; text-align: justify;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</content><link href="https://pythonbegginer.blogspot.com/feeds/6812101044647041506/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/String-Operations-in-Python-pythonblog.html.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6812101044647041506" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6812101044647041506" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/String-Operations-in-Python-pythonblog.html.html" rel="alternate" title="String Operations in Python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIZttcAYDUWYut2x87ID3C0USOgSrusYnGUhMBVpW9GKcLIfZHoe7Z0xSr7pOJ8loXG-uoRoxoH9QeDNXKxQOjkLHKEd2FmsZPKC8t5en9BmH18Nw-QEBwJw3l4LAg6Wpnqbz9j0F3_Ss/s72-w400-h225-c/hitesh-choudhary-D9Zow2REm8U-unsplash.jpg" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-6820261394100816502</id><published>2020-05-01T12:38:00.004+05:30</published><updated>2020-05-29T09:33:14.454+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Basics"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Introduction to the python - Letsprogram</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div style="text-align: left;"&gt;
&lt;b style="font-family: arial, helvetica, sans-serif; font-size: xx-large;"&gt;Basic concepts in python&lt;/b&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;b style="font-family: arial, helvetica, sans-serif; font-size: xx-large;"&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;b&gt;Comments&lt;/b&gt; in Python start with the hash character, #, and extend to the end of the physical line.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;A comment may appear at the start of a line or following whitespace or code, but not within a string literal. A hash character within a string literal is just a hash character. Since comments are to clarify code and are not interpreted by Python, they may be omitted when typing in examples.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="highlight-python3 notranslate"&gt;
&lt;div class="highlight"&gt;
&lt;pre&gt;&lt;span style="background-color: #666666; font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;"&gt;&lt;span class="c1"&gt;# this is the first comment                                             &lt;/span&gt;
&lt;span class="n"&gt;spam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="c1"&gt;# and this is the second comment                              &lt;/span&gt;
          &lt;span class="c1"&gt;# ... and now a third!                                        &lt;/span&gt;
&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"# This is not a comment because it's inside quotes."            &lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-size: large;"&gt;Let’s try some basic Python commands. Start the interpreter and wait for the python prompt, &amp;gt;&amp;gt;&amp;gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: x-large;"&gt;&lt;b&gt;Numbers&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-size: large;"&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;The equal sign (&lt;/span&gt;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; color: #222222; font-family: monospace, sans-serif; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;=&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;) is used to assign a value to a variable. Afterward, no result is displayed before the next interactive prompt. In Python, we need no to define the variable before using it. But&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&lt;span style="font-size: large;"&gt;If a variable is not “defined” (assigned a value), trying to use it will give you an error&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&lt;span style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&lt;span style="font-size: large;"&gt;Using&amp;nbsp; (/)&amp;nbsp; gives you float value of remainder using&amp;nbsp; (//) gives integer value of the remainder.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&lt;span style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style="font-size: large;"&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;In addition to&amp;nbsp;&lt;/span&gt;&lt;code class="xref py py-class docutils literal notranslate" style="background-color: transparent; border-radius: 3px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;span style="font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;code class="xref py py-class docutils literal notranslate" style="background-color: transparent; border-radius: 3px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;span style="font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;"&gt;float&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;, Python supports other types of numbers, such as&amp;nbsp;&lt;/span&gt;&lt;code class="xref py py-class docutils literal notranslate" style="background-color: transparent; border-radius: 3px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;span style="font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;"&gt;Decimal&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;code class="xref py py-class docutils literal notranslate" style="background-color: transparent; border-radius: 3px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;&lt;span style="font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;"&gt;Fraction&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;. Python also has built-in support for&amp;nbsp;&lt;/span&gt;&lt;span class="std std-ref" style="background-color: white; text-align: justify; text-decoration-line: none;"&gt;&lt;span style="font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;"&gt;complex numbers&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&amp;nbsp;and uses the&amp;nbsp;&lt;/span&gt;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; color: #222222; font-family: monospace, sans-serif; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;j&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&amp;nbsp;or&amp;nbsp;&lt;/span&gt;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; color: #222222; font-family: monospace, sans-serif; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;J&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&amp;nbsp;suffix to indicate the imaginary part (e.g.&amp;nbsp;&lt;/span&gt;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; color: #222222; font-family: monospace, sans-serif; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;3+5j&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;).&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="-webkit-text-stroke-width: 0px; color: black; font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style="-webkit-text-stroke-width: 0px; color: black; font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; margin: 0px; orphans: 2; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;span style="color: #444444; font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: large;"&gt;&lt;b&gt;All concepts have an example given below&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style="font-size: large;"&gt;&lt;span style="background-color: white; color: #222222; font-family: &amp;quot;lucida grande&amp;quot; , &amp;quot;arial&amp;quot; , sans-serif; text-align: justify;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src="https://gist.github.com/signatureratings/100829b2cdf49feebcccbbcd05d63302.js"&gt;&lt;/script&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: x-large;"&gt;&lt;b&gt;Strings&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;/div&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;( \ ) is used to escape quotes in a string.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;"&gt;&lt;span style="font-size: large;"&gt;Y&lt;/span&gt;&lt;span style="font-size: large;"&gt;&lt;span style="background-color: white; text-align: justify;"&gt;ou can use&amp;nbsp;&lt;/span&gt;&lt;em style="background-color: white; text-align: justify;"&gt;raw strings&lt;/em&gt;&lt;span style="background-color: white; text-align: justify;"&gt;&amp;nbsp;by adding an&amp;nbsp;&lt;/span&gt;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; padding: 0px 1px; text-align: justify;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;r&lt;/span&gt;&lt;/code&gt;&lt;span style="background-color: white; text-align: justify;"&gt;&amp;nbsp;before the first quote&amp;nbsp;&lt;/span&gt;it makes sure to ignore the meaning of ( \n ).&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;Strings can be concatenated (glued together) with the&amp;nbsp;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;+&lt;/span&gt;&lt;/code&gt;&amp;nbsp;operator, and repeated with&amp;nbsp;&lt;code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; padding: 0px 1px;"&gt;&lt;span class="pre" style="hyphens: none;"&gt;*&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;span style="background-color: white;"&gt;Two or more strings beside each other are concatenated automatically.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div style="-webkit-text-stroke-width: 0px; color: black; font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style="-webkit-text-stroke-width: 0px; color: black; font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; margin: 0px; orphans: 2; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;span style="color: #444444; font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif; font-size: large;"&gt;&lt;b&gt;All concepts have an example given below&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="highlight-python3 notranslate" style="-webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: &amp;quot;Lucida Grande&amp;quot;, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; orphans: 2; position: relative; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;div class="highlight" style="background: rgb(238, 255, 204);"&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;script src="https://gist.github.com/signatureratings/8cecb6641b2958ce54462397689d0325.js"&gt;&lt;/script&gt;

&lt;/div&gt;
</content><link href="https://pythonbegginer.blogspot.com/feeds/6820261394100816502/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/introduction-to-python.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6820261394100816502" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/6820261394100816502" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/05/introduction-to-python.html" rel="alternate" title="Introduction to the python - Letsprogram" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><thr:total>0</thr:total><georss:featurename>Telangana, India</georss:featurename><georss:point>18.1124372 79.019299699999991</georss:point><georss:box>14.246392699999998 73.8557257 21.9784817 84.182873699999988</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-1590482478957698376</id><published>2020-04-30T14:59:00.000+05:30</published><updated>2020-04-30T14:59:56.957+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="installation"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">How to install python in your computer</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="line874" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;Before you start, you will need Python on your computer.&lt;span class="anchor" id="line-3"&gt;&lt;/span&gt;&lt;span class="anchor" id="line-4"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line874" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;Check whether you already have an up to date version of Python installed by entering&amp;nbsp;&lt;tt class="backtick"&gt;python&lt;/tt&gt;&amp;nbsp;in a command-line window. If you see a response from a Python interpreter it will include a version number in its initial display.&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8-0JWDeM7fAIa7VtMMJZdMrpeanVEr3vgL5ks9wN9BH82IWTIOEOykunaEaHBEM5ddK_njdoXUIyyu4fW2LDvL5ioTTXA5O_C-6eFvBw6GL6sDXflJbuyVuB0nBHV_1EQqsGBjL-lCXA/s1600/Screenshot+%252841%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="python command to know the version" border="0" data-original-height="436" data-original-width="904" height="308" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8-0JWDeM7fAIa7VtMMJZdMrpeanVEr3vgL5ks9wN9BH82IWTIOEOykunaEaHBEM5ddK_njdoXUIyyu4fW2LDvL5ioTTXA5O_C-6eFvBw6GL6sDXflJbuyVuB0nBHV_1EQqsGBjL-lCXA/s640/Screenshot+%252841%2529.png" title="python command to know the version" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;When you use &lt;/span&gt;&lt;span style="font-family: Courier New, Courier, monospace; font-size: large;"&gt;python --version&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt; it displays version when you use the only &lt;/span&gt;&lt;span style="font-family: Courier New, Courier, monospace; font-size: large;"&gt;python&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt; it opens the python shell in the command line. If it is showing you the version then it means you had the python in your system.&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;Generally, any Python 3.x version will do, As of now, the latest version is 3.8.2 when I wrote this post. Python makes every attempt to maintain backward compatibility within major Python versions. Python 2.x and Python 3.x are intentionally not fully compatible. If&amp;nbsp;&lt;tt class="backtick"&gt;python&lt;/tt&gt;&amp;nbsp;starts a Python 2.x interpreter, try entering&amp;nbsp;&lt;tt class="backtick"&gt;python3&lt;/tt&gt;&amp;nbsp;and see if an up to date version is already installed.&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;Go to the &lt;a href="https://www.python.org/downloads/" target="_blank"&gt;Python downloads&lt;/a&gt; page and download your relatable file according to the operating system, no of bits, and use of python for your work.&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIpwG1XfLTRmkSp2JmamqioVyjkhXJOjAe2XHiYCyqQvs-QgIdUN1mUFkrZXb766n9OEnTbSwY1ZutfbF_kXelSi4iptWjz7wagdFj3VvgSSYUQsM6zse5TxRAPL9nXW1HBzugWLsYQ8A/s1600/Screenshot+%252843%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="526" data-original-width="1600" height="210" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIpwG1XfLTRmkSp2JmamqioVyjkhXJOjAe2XHiYCyqQvs-QgIdUN1mUFkrZXb766n9OEnTbSwY1ZutfbF_kXelSi4iptWjz7wagdFj3VvgSSYUQsM6zse5TxRAPL9nXW1HBzugWLsYQ8A/s640/Screenshot+%252843%2529.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;On Windows, you have a choice between 32-bit (labeled&amp;nbsp;&lt;strong&gt;x86&lt;/strong&gt;) and 64-bit (labeled&amp;nbsp;&lt;strong&gt;x86-64&lt;/strong&gt;) versions, and several flavors of the installer for each. The Python core team thinks there should be a default you don't have to stop and think about, so the yellow download button on the main download page gets you the "x86 executable installer" choice. This is actually a fine choice: you don't&amp;nbsp;&lt;em&gt;need&lt;/em&gt;&amp;nbsp;the 64-bit version even if you have 64-bit Windows, the 32-bit Python will work just fine.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862"&gt;
&lt;span style="background-color: #cccccc;"&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;NOTE:&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&amp;nbsp;Check whether you are downloading 64 bit or 32 bit to your windows system.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;After downloading your executable file install the python in your system. You can go with the installation flow normally it is easy.&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;You will get python shell, manuals, modules, and IDLE of python. Yow may use any other Python IDE's like Pycharm, anaconda, Visual code any other you prefer.IDE makes the work environment good and fast.&lt;/span&gt;&lt;/div&gt;
&lt;div class="line862" style="background-color: white;"&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link href="https://pythonbegginer.blogspot.com/feeds/1590482478957698376/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/04/how-to-install-python-in-your-computer.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/1590482478957698376" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/1590482478957698376" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/04/how-to-install-python-in-your-computer.html" rel="alternate" title="How to install python in your computer" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8-0JWDeM7fAIa7VtMMJZdMrpeanVEr3vgL5ks9wN9BH82IWTIOEOykunaEaHBEM5ddK_njdoXUIyyu4fW2LDvL5ioTTXA5O_C-6eFvBw6GL6sDXflJbuyVuB0nBHV_1EQqsGBjL-lCXA/s72-c/Screenshot+%252841%2529.png" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4427171222356646557.post-4864726379257566661</id><published>2020-04-30T14:06:00.000+05:30</published><updated>2020-04-30T19:55:17.785+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="introduction"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type="text">Why python is so famous</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;Python is an easy programming language whether you are a first-time programmer or you have experienced in many other programming languages.&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP6ug5Ex3VYbfyZjiuFpm2jEWu4X3IV6Sj0eG0s434NjYqg2eYa2OD8YOfUrNKa90jYNEC_QzGjn_OwHXzGGS7GGqh5S3owV_5dSN0aJAC_2N-r3A9U3w5IRWW8qfhCE4KIWJlvUL4Wew/s1600/python.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Python programming language" border="0" data-original-height="500" data-original-width="840" height="379" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP6ug5Ex3VYbfyZjiuFpm2jEWu4X3IV6Sj0eG0s434NjYqg2eYa2OD8YOfUrNKa90jYNEC_QzGjn_OwHXzGGS7GGqh5S3owV_5dSN0aJAC_2N-r3A9U3w5IRWW8qfhCE4KIWJlvUL4Wew/s640/python.jpeg" title="Python programming language" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;Python is a high level, interpreted, and general-purpose programming language. Python came into the market before Java(1995) in the year 1991(first release) by Guido van Rossum. Python code is very easy to read with its notable significant whitespace.&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;Python is the easiest language available in the market and Python had the largest community here, They make programming more effective. Many Big companies use python as the main language or support language like Google, Youtube, Dropbox, and yahoo.&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #f9f9f9; color: #030303; white-space: pre-wrap;"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;The reason behind it is there is a huge number of libraries available in the market, many companies and developers are using it and it can be implemented in many areas. When a huge set of libraries are involving it makes our work speed this is one of the reasons why Python is chosen over other languages.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #f9f9f9; color: #030303; white-space: pre-wrap;"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #f9f9f9; color: #030303; white-space: pre-wrap;"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;Python is used in ML, AI, Blockchain ..etc. and Frameworks like Django are very famous in web technology nowadays.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #f9f9f9; color: #030303; white-space: pre-wrap;"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;It is worth to learn python.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #f9f9f9; color: #030303; white-space: pre-wrap;"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="line874" style="background-color: white;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;u&gt;Some of Python's notable features:&lt;/u&gt;&lt;span class="anchor" id="line-4"&gt;&lt;/span&gt;&lt;span class="anchor" id="line-5"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul style="background-color: white;"&gt;
&lt;li style="list-style: url(&amp;quot;../img/bullet.gif&amp;quot;);"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;Uses an elegant syntax, making the programs you write easier to read.&lt;span class="anchor" id="line-6"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="list-style: url(&amp;quot;../img/bullet.gif&amp;quot;);"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;It is an easy-to-use language that makes it simple to get your program working. This makes Python ideal for prototype development and other ad-hoc programming tasks, without compromising maintainability.&lt;span class="anchor" id="line-7"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="list-style: url(&amp;quot;../img/bullet.gif&amp;quot;);"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;It comes with a large standard library that supports many common programming tasks such as connecting to web servers, searching text with regular expressions, reading, and modifying files.&lt;span class="anchor" id="line-8"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="list-style: url(&amp;quot;../img/bullet.gif&amp;quot;);"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;Python's interactive mode makes it easy to test short snippets of code. There's also a bundled development environment called IDLE.&lt;span class="anchor" id="line-9"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="list-style: url(&amp;quot;../img/bullet.gif&amp;quot;);"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;It is easily extended by adding new modules implemented in a compiled language such as C or C++.&lt;span class="anchor" id="line-10"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="list-style: url(&amp;quot;../img/bullet.gif&amp;quot;);"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;It can also be embedded into an application to provide a programmable interface.&lt;span class="anchor" id="line-11"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="list-style: url(&amp;quot;../img/bullet.gif&amp;quot;);"&gt;&lt;div class="line862" style="margin-bottom: 0.25em; margin-top: 0.25em;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;Runs anywhere, including&amp;nbsp;Mac OS X,&amp;nbsp;Windows,&amp;nbsp;Linux, and&amp;nbsp;Unix, with unofficial builds also available for&amp;nbsp;Android&amp;nbsp;and iOS.&lt;span class="anchor" id="line-12"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="list-style: url(&amp;quot;../img/bullet.gif&amp;quot;);"&gt;&lt;div class="line862" style="margin-bottom: 0.25em; margin-top: 0.25em;"&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;It is free software in two senses. It doesn't cost anything to download or use Python, or to include it in your application. Python can also be freely modified and re-distributed because while the language is copyrighted it's available under&amp;nbsp;an open-source license.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #f9f9f9; color: #030303; white-space: pre-wrap;"&gt;&lt;span style="font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link href="https://pythonbegginer.blogspot.com/feeds/4864726379257566661/comments/default" rel="replies" title="Post Comments" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/04/why-python-is-so-famous.html#comment-form" rel="replies" title="0 Comments" type="text/html"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/4864726379257566661" rel="edit" type="application/atom+xml"/><link href="https://www.blogger.com/feeds/4427171222356646557/posts/default/4864726379257566661" rel="self" type="application/atom+xml"/><link href="https://pythonbegginer.blogspot.com/2020/04/why-python-is-so-famous.html" rel="alternate" title="Why python is so famous" type="text/html"/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image height="16" rel="http://schemas.google.com/g/2005#thumbnail" src="https://img1.blogblog.com/img/b16-rounded.gif" width="16"/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP6ug5Ex3VYbfyZjiuFpm2jEWu4X3IV6Sj0eG0s434NjYqg2eYa2OD8YOfUrNKa90jYNEC_QzGjn_OwHXzGGS7GGqh5S3owV_5dSN0aJAC_2N-r3A9U3w5IRWW8qfhCE4KIWJlvUL4Wew/s72-c/python.jpeg" width="72"/><thr:total>0</thr:total></entry></feed>