<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: abhinav2499</title>
    <description>The latest articles on DEV Community by abhinav2499 (@abhinav2499).</description>
    <link>https://dev.to/abhinav2499</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F516983%2Fbc465248-c042-4c0a-bff5-2ca7cb1770d7.png</url>
      <title>DEV Community: abhinav2499</title>
      <link>https://dev.to/abhinav2499</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhinav2499"/>
    <language>en</language>
    <item>
      <title>Area of Circle: Explained</title>
      <dc:creator>abhinav2499</dc:creator>
      <pubDate>Wed, 17 Aug 2022 04:30:00 +0000</pubDate>
      <link>https://dev.to/abhinav2499/area-of-circle-explained-22hn</link>
      <guid>https://dev.to/abhinav2499/area-of-circle-explained-22hn</guid>
      <description>&lt;p&gt;In simple terms, we can say that a circle is a round-shaped figure that has no corners or edges. In geometry, a circle can be defined as a closed, two-dimensional curved shape in which the distance of all the points on the circle is same from it’s centre; this distance is also called radius of the circle. Few things around us that are circular in shape are bike wheels, a DVD and coins. We all know that the area of a circle is πr^2, but how? In this blog we’ll try to answer that question.&lt;br&gt;
Let’s imagine taking a tomato and slicing it into 4 equal parts, now if we interlaced these parts as shown in the below image we’ll get a figure which barely resembles a rectangle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ku4iJWi1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dh1s5asvwfifnlpy7hv2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ku4iJWi1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dh1s5asvwfifnlpy7hv2.png" alt="Image description" width="880" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But what if we take another tomato, slice it into 8 equal parts and interlaced them as shown in the below image? We’ll get a figure which somewhat more resembles a rectangle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JYNNEE-I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbfzos37539y6s5lftu0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JYNNEE-I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbfzos37539y6s5lftu0.png" alt="Image description" width="880" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So if we divide the circle into even more smaller pieces, we can see that every time the shape becomes more like a rectangle.&lt;br&gt;
But how small must we divide the circle before we get a perfect rectangle? It turns out that we can keep on dividing the circle into smaller and smaller pieces we can make but the answer is to divide the circle infinitely many times until we can’t distinguish the lines and eventually the circle can now become a perfect rectangle as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U9qOiu4m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/isfd8eqwzvj6f0wsfzda.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U9qOiu4m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/isfd8eqwzvj6f0wsfzda.png" alt="Image description" width="640" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, the area of the circle = area of rectangle = base x height&lt;br&gt;
As we can see, the radius of the circle becomes the bases of the rectangle while the half of it’s &lt;a href="https://en.wikipedia.org/wiki/Circumference"&gt;circumference&lt;/a&gt; becomes the height of the rectangle.&lt;br&gt;
Therefore, area of circle = r x 2πr/2, where 2πr is the circumference of the circle.&lt;br&gt;
This gives us the area of circle to be πr^2.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Pattern Matching with Regular Expressions in Python: Part 1</title>
      <dc:creator>abhinav2499</dc:creator>
      <pubDate>Tue, 16 Aug 2022 04:43:00 +0000</pubDate>
      <link>https://dev.to/abhinav2499/pattern-matching-with-regular-expressions-in-python-part-1-52c1</link>
      <guid>https://dev.to/abhinav2499/pattern-matching-with-regular-expressions-in-python-part-1-52c1</guid>
      <description>&lt;p&gt;We’re all familiar with searching for text by pressing CTRL + F and typing in the words that we’re looking for. Regular expressions go one step further: they allow us to specify a pattern of text to search for. Someone may not know a business’s exact landline number, but if they live in India, they know it’ll be 2 to 4 digits, followed by a hyphen, and then seven more digits. This is how we, as a human, know a phone number when we see it: 524-2768494 is a landline number, but 5,242,768,494 is not.&lt;br&gt;
Regular expressions are helpful, but not many people know about them even though most of the modern text editors and word processors such as Microsoft Word or LibreOffice, have find and find-and-replace features that can search based on regular expressions. They are huge time-savers not just for software users but also for programmers.&lt;br&gt;
This series is divided into two parts, in this part 1, we’ll start by writing a program to find text patterns without using regular expressions and then see how to use regular expressions to make the code much concise and clean. We’ll use basic matching with regular expressions and then in the next part we’ll move on to some of its more powerful features.&lt;br&gt;
&lt;strong&gt;Finding Patterns of Text Without Regular Expressions&lt;/strong&gt;&lt;br&gt;
Let’s say we want to find a landline number in a string which contains 3 numbers, followed by a hyphen and then 7 more numbers such as 524-2768494.&lt;br&gt;
Let’s use a function named isPhoneNumber() to check whether a string matches this pattern, returning either True or False. Open a Jupyter notebook and enter the following code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bJz82Hie--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vt6hxgtfcxber2r9ayfz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bJz82Hie--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vt6hxgtfcxber2r9ayfz.png" alt="Image description" width="880" height="889"&gt;&lt;/a&gt;&lt;br&gt;
The isPhoneNumber() function has code that does several checks to see whether the string in text is a valid landline number. If any of these checks fail, the function returns False. First, the code checks that the string is exactly 11 characters. Then, it checks that the area code (that is, the first three characters in text) consists of only numeric characters. The rest of the function checks that the string follows the pattern of a landline number. The number must have a hyphen followed by seven more numeric characters.&lt;br&gt;
Calling isPhoneNumber() with the argument ‘524-2768494’ will return True while calling isPhoneNumber() with ‘Abhinav Yadav’ will return False as the first test fails because ‘Abhinav Yadav’ is not 11 characters long.&lt;br&gt;
We would have to add even more code to find this pattern of text in a larger string, it could be millions of characters long and the program would still run in less than a second similar to a program with regular expression but regular expressions make it quicker to write these programs.&lt;br&gt;
&lt;strong&gt;Finding Patterns of Text With Regular Expressions&lt;/strong&gt;&lt;br&gt;
The previous landline number finding program works, but it uses a lot of code to do something limited: This isPhoneNumber() function is 12 lines long but can find only one pattern of phone numbers. What about a phone number formatted like 0524-2768494 or (524) 2768494? What if the phone number only had two digits before the hyphen, like 11-2768494? The isPhoneNumber() function would fail to validate them. We could add yet more code for these additional patterns, but there’s an easier way.&lt;br&gt;
Regular expressions, called regex for short, are descriptions for a pattern of text. For example, a \d in a regex stands for a digit character, that is, any single numeral from 0 to 9. The regex \d\d\d-\d\d\d\d\d\d\d is used by Python to match the same text the previous isPhoneNumber() function did: a string of three numbers, a hyphen followed by seven more numbers. Any other string would not match the \d\d\d-\d\d\d\d\d\d\d regex.&lt;br&gt;
But a regex can be more sophisticated as well. For example, adding a 6 in curly brackets ({6}) after a pattern is like saying, “Match this pattern 6 times.” So the slightly shorter regex \d{3}-\d{7} also matches the correct phone number format.&lt;br&gt;
All the regex functions in Python are in re module so we’ll have to import it first. To create a regex that matches the phone number pattern, enter the following into Jupyter notebook.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---7ccFuxV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpnr5keo66om9s0p9vi9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---7ccFuxV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpnr5keo66om9s0p9vi9.png" alt="Image description" width="880" height="183"&gt;&lt;/a&gt;&lt;br&gt;
Passing a string value representing our regex to re.compile returns a Regex pattern object which is stored in phoneNumberRegex. Then we call search() on phoneNumberRegex and pass search() the string we want to search a match for. The search() method will return None if the regex pattern is not found in the string. If the pattern is found, the search() method returns a Match() object. Match objects have a group() method that will return the actual matched text from the searched string. The result of the search gets stored in the variable output. In this example, we know that our pattern will be found in the string, so we know that a Match object Weill be returned. Knowing that output contains a Match object and not the null value None, we can call group() on output to return the match. Writing output.group() inside our print statement displays the whole match, 524-2768494.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
