<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[DataDiary]]></title><description><![CDATA[A personal blog sharing what i am  learning in my developer journey ]]></description><link>https://pdlmanoj.com.np</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 16:30:26 GMT</lastBuildDate><atom:link href="https://pdlmanoj.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Session 2 : A Guide to Operators, If-Else Statements, and Loops]]></title><description><![CDATA[In this post, we will learn about operators, loops, and conditional expressions, which are fundamental components in Python.

Just imagine, you'd like to,

Manipulate data: Operators enable you to perform calculations, comparisons, and assignments, l...]]></description><link>https://pdlmanoj.com.np/session-2-a-guide-to-operators-if-else-statements-and-loops</link><guid isPermaLink="true">https://pdlmanoj.com.np/session-2-a-guide-to-operators-if-else-statements-and-loops</guid><category><![CDATA[#python-operators]]></category><category><![CDATA[loops in python]]></category><category><![CDATA[python beginner]]></category><dc:creator><![CDATA[Manoj Paudel]]></dc:creator><pubDate>Thu, 23 May 2024 07:20:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1716364128835/3b86fa1c-e2c7-45b1-b6ca-568a9c6353b2.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>In this post,</strong> we will learn about operators, loops, and conditional expressions, which are fundamental components in Python.</p>
<p><img src="https://i.pinimg.com/originals/10/d9/90/10d99096ef9d4d0dab6123b17e5602da.jpg" alt="Funny Man in White Shirt and Tie with Humorous Words" class="image--center mx-auto" /></p>
<p><strong>Just imagine</strong>, you'd like to,</p>
<ul>
<li><p><strong>Manipulate data</strong>: <strong>Operators</strong> enable you to perform calculations, comparisons, and assignments, like "calculate the 5 power 7 ? ".</p>
</li>
<li><p><strong>Make decisions</strong>: <strong>If-else</strong> conditions let your program make choices based on data, like "if it's raining, take an umbrella".</p>
</li>
<li><p><strong>Repeat tasks</strong>: <strong>Loops</strong> help you perform actions multiple times, like "printing I love you 5 times".</p>
</li>
</ul>
<p><em>Mastering these fundamentals concept will help you write efficient, logical, and readable code, to become a good Python programmer!</em></p>
<hr />
<h2 id="heading-operators">Operators</h2>
<p><strong>In python,</strong> operators are special symbols or keywords which are used to perform operations on variables and values. Let's learn different types of operators in python,</p>
<ol>
<li><p><strong><mark>Arithmetic Operators</mark></strong></p>
<p> We used arithmetic operators for basic mathematical operations like,</p>
<ul>
<li><p><code>+</code> : Addition</p>
</li>
<li><p><code>-</code> : Subtraction</p>
</li>
<li><p><code>*</code> : Multiplication</p>
</li>
<li><p><code>/</code> : Division</p>
</li>
<li><p><code>%</code> : Modulus (remainder of division)</p>
</li>
<li><p><code>**</code> : Exponentiation (power of)</p>
</li>
<li><p><code>//</code> : Integer Division (returns, the nearest integer lower than the result)</p>
<pre><code class="lang-python">  print(<span class="hljs-number">5</span>+<span class="hljs-number">6</span>)     <span class="hljs-comment"># 11 </span>
  print(<span class="hljs-number">5</span><span class="hljs-number">-6</span>)     <span class="hljs-comment"># -1    </span>
  print(<span class="hljs-number">5</span>*<span class="hljs-number">6</span>)     <span class="hljs-comment"># 30    </span>
  print(<span class="hljs-number">5</span>/<span class="hljs-number">2</span>)     <span class="hljs-comment"># 2.5   </span>
  print(<span class="hljs-number">5</span>//<span class="hljs-number">2</span>)    <span class="hljs-comment"># 2    </span>
  print(<span class="hljs-number">5</span>%<span class="hljs-number">2</span>)     <span class="hljs-comment"># 1     </span>
  print(<span class="hljs-number">5</span>**<span class="hljs-number">2</span>)    <span class="hljs-comment"># 25</span>
</code></pre>
</li>
</ul>
</li>
<li><p><strong><mark>Relational Operators</mark></strong></p>
<p> We used relational operators to compare two values and return result in boolean.</p>
<ul>
<li><p><code>==</code> : Equal to</p>
</li>
<li><p><code>!=</code> : Not equal to</p>
</li>
<li><p><code>&gt;</code> : Greater than</p>
</li>
<li><p><code>&lt;</code> : Less than</p>
</li>
<li><p><code>&gt;=</code> : Greater than or equal to</p>
</li>
<li><p><code>&lt;=</code> : Less than or equal to</p>
<pre><code class="lang-python">  print(<span class="hljs-number">4</span>&gt;<span class="hljs-number">5</span>)     <span class="hljs-comment"># False</span>
  print(<span class="hljs-number">4</span>&lt;<span class="hljs-number">5</span>)     <span class="hljs-comment"># True</span>
  print(<span class="hljs-number">4</span>&gt;=<span class="hljs-number">5</span>)    <span class="hljs-comment"># True</span>
  print(<span class="hljs-number">4</span>&lt;=<span class="hljs-number">5</span>)    <span class="hljs-comment"># True</span>
  print(<span class="hljs-number">4</span>==<span class="hljs-number">4</span>)    <span class="hljs-comment"># True</span>
  print(<span class="hljs-number">4</span>!=<span class="hljs-number">4</span>)    <span class="hljs-comment"># False</span>
</code></pre>
</li>
</ul>
</li>
<li><p><strong><mark>Logical Operators</mark></strong></p>
<p> Logical operators are used to combine conditional statements.</p>
<ul>
<li><p><code>and</code> : Returns <strong>True</strong> if both statements are true</p>
</li>
<li><p><code>or</code> : Returns <strong>True</strong> if one of the statements is true</p>
</li>
<li><p><code>not</code> : If True return <strong>False</strong> | If False return <strong>True</strong></p>
<pre><code class="lang-python">  print(<span class="hljs-number">1</span> <span class="hljs-keyword">and</span> <span class="hljs-number">0</span>)    <span class="hljs-comment"># O [False]</span>
  print(<span class="hljs-number">0</span> <span class="hljs-keyword">or</span> <span class="hljs-number">1</span>)     <span class="hljs-comment"># 1 [True]</span>
  print(<span class="hljs-keyword">not</span> <span class="hljs-number">1</span>)      <span class="hljs-comment"># False</span>
</code></pre>
</li>
</ul>
</li>
<li><p><strong><mark>Bitwise Operators</mark></strong></p>
<p> We use bitwise operators only to operate on bits or binary digits.</p>
<ul>
<li><p><code>&amp;</code> : AND</p>
</li>
<li><p><code>|</code> : OR</p>
</li>
<li><p><code>^</code> : XOR (exclusive OR)</p>
</li>
<li><p><code>~</code> : NOT (inverts all the bits)</p>
</li>
<li><p><code>&lt;&lt;</code> : Left shift</p>
</li>
<li><p><code>&gt;&gt;</code> : Right shift</p>
<pre><code class="lang-python">  print(<span class="hljs-number">2</span>&amp;<span class="hljs-number">3</span>)    <span class="hljs-comment"># 2</span>
  print(<span class="hljs-number">2</span>|<span class="hljs-number">3</span>)    <span class="hljs-comment"># 3</span>
  print(<span class="hljs-number">2</span>^<span class="hljs-number">3</span>)    <span class="hljs-comment"># 1</span>
  print(~<span class="hljs-number">3</span>)     <span class="hljs-comment">#-4</span>
  print(<span class="hljs-number">4</span>&gt;&gt;<span class="hljs-number">2</span>)   <span class="hljs-comment"># 1</span>
  print(<span class="hljs-number">5</span>&lt;&lt;<span class="hljs-number">2</span>)   <span class="hljs-comment"># 20</span>
</code></pre>
</li>
</ul>
</li>
</ol>
<p>    <strong>In data science</strong>, bitwise operators are not commonly used may be we used <code>&amp; (AND) ,| (OR)</code> operators for image processing , computer vision projects. But, typically more relevant in low-level programming, system programming. To understand more : <a target="_blank" href="https://www.youtube.com/watch?v=F_UIOvfmsew"><strong><em>Link</em></strong></a></p>
<ol start="5">
<li><p><strong><mark>Assignment Operators</mark></strong></p>
<p> Assignment operators <code>=</code> is used to assign a value to a variable.</p>
<pre><code class="lang-python"> a = <span class="hljs-number">2</span> <span class="hljs-comment"># assign value 2 to variable a</span>

 a += <span class="hljs-number">2</span> <span class="hljs-comment"># means: a = a + 2</span>
 print(a) <span class="hljs-comment"># 4</span>
</code></pre>
</li>
<li><p><strong><mark>Identity Operators</mark></strong></p>
<p> Identity operators are used to check if two values are located at same memory location or not.</p>
<ul>
<li><p><code>is</code> : <strong>True</strong> if the operands are identical (refer to the same object)</p>
</li>
<li><p><code>is not</code> : <strong>True</strong> if the operands are not identical (do not refer to the same object)</p>
<pre><code class="lang-python">  a = <span class="hljs-number">10</span>
  b = <span class="hljs-number">10</span>
  c = a
  l1 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>]
  l2 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>]

  print(a <span class="hljs-keyword">is</span> b)    <span class="hljs-comment"># True</span>
  print(a <span class="hljs-keyword">is</span> c)    <span class="hljs-comment"># True</span>
  print(c <span class="hljs-keyword">is</span> b)    <span class="hljs-comment"># True</span>
  print(l1 <span class="hljs-keyword">is</span> l2)  <span class="hljs-comment"># False</span>
</code></pre>
</li>
</ul>
</li>
</ol>
<p>    Here, <code>l1</code> and <code>l2</code> have same list but they are not identical because it store both in different memory location although they have same list.</p>
<ol start="7">
<li><p><strong><mark>Membership Operators</mark></strong></p>
<p> Membership operators are used to check if a sequence is presented in or not.</p>
<ul>
<li><p><code>in</code> : <strong>True</strong> if value found in a sequence</p>
</li>
<li><p><code>not in</code> : <strong>True</strong> if value not found in a sequence</p>
<pre><code class="lang-python">  print(<span class="hljs-string">'P'</span> <span class="hljs-keyword">in</span> <span class="hljs-string">'Python'</span>)        <span class="hljs-comment"># True</span>
  print(<span class="hljs-string">'P'</span> <span class="hljs-keyword">in</span> <span class="hljs-string">'python'</span>)        <span class="hljs-comment"># False</span>
  print(<span class="hljs-number">1</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>])   <span class="hljs-comment"># False</span>
</code></pre>
</li>
</ul>
</li>
</ol>
<p><mark>Now that you've learned the basics of </mark> <strong><mark>operators</mark></strong> <mark> in Python, it's time to put that knowledge into practice.</mark></p>
<p><strong>Task:</strong><code>WAP to find the sum of 3 digits number given by the user. Eg. Input: 345 | Output: 12</code></p>
<hr />
<h2 id="heading-if-else-condition">If-Else Condition</h2>
<p>In Python, <strong>if-else statements</strong> are essential control flow tools that enable you to make decisions based on specific conditions. Here’s a simple example to understanding if-else statements in Python.</p>
<pre><code class="lang-python">age = <span class="hljs-number">15</span>
<span class="hljs-keyword">if</span> age &gt;= <span class="hljs-number">18</span>:
    print(<span class="hljs-string">"You are eligible for driving license"</span>)
<span class="hljs-keyword">else</span>:
    print(<span class="hljs-string">"You are a minor."</span>)

<span class="hljs-comment"># Output: You are a minor.</span>
</code></pre>
<p>Here, <code>if-else</code> statement allows you to execute one block of code if the condition is True and another block of code if the condition is False. Since <code>age</code> is 15, the condition <code>age &gt;= 18</code> is False, so the message "You are a minor." is printed.</p>
<p>Moreover, for more complex decision-making, we use <code>elif</code> ("else if") to check multiple conditions. It lets you test several conditions in sequence until one is found to be true. Here's a simple login program to check whether the user input email and password are valid or not.</p>
<pre><code class="lang-python"><span class="hljs-comment"># valid_email -&gt; datadiary@gmail.com</span>
<span class="hljs-comment"># password -&gt; datadiary</span>
email = input(<span class="hljs-string">'enter email: '</span>)
password = input(<span class="hljs-string">'enter password: '</span>)

<span class="hljs-keyword">if</span> email == <span class="hljs-string">'datadiary@gmail.com'</span> <span class="hljs-keyword">and</span> password == <span class="hljs-string">'datadiary'</span>:
  print(<span class="hljs-string">'Welcome'</span>)
<span class="hljs-comment"># if email valid but password  wrong</span>
<span class="hljs-keyword">elif</span> email == <span class="hljs-string">'datadiary@gmail.com'</span> <span class="hljs-keyword">and</span> password != <span class="hljs-string">'datadiary'</span>:
  <span class="hljs-comment"># tell the user</span>
  print(<span class="hljs-string">'Incorrect password'</span>)
    <span class="hljs-comment"># Reenter password</span>
  password = input(<span class="hljs-string">'enter password again: '</span>)
  <span class="hljs-keyword">if</span> password == <span class="hljs-string">'datadiary'</span>:
    print(<span class="hljs-string">'Welcome,finally!'</span>)
  <span class="hljs-keyword">else</span>:
    print(<span class="hljs-string">'password invalid'</span>)
<span class="hljs-keyword">else</span>:
  print(<span class="hljs-string">'No correct input.'</span>)
</code></pre>
<p><mark>Now, try to solve one question on </mark> <strong><mark>if-else </mark></strong> <mark>statement,</mark></p>
<p><strong>Task :</strong><code>WAP that determines the category of a person based on their given age.</code></p>
<ul>
<li><p><code>"Child"</code> if the age is 0-12</p>
</li>
<li><p><code>"Teenager"</code> if the age is 13-19</p>
</li>
<li><p><code>"Adult"</code> if the age is 20-59</p>
</li>
<li><p><code>"Senior"</code> if the age is 60 or above</p>
</li>
</ul>
<hr />
<h2 id="heading-modules">Modules</h2>
<p><strong>Python Module</strong> is a file that contains built-in functions, classes, and variables. There are many <strong>Python modules</strong>, each with its specific work. In this section, we are going to learn about <strong><em>math, keywords, random and datetime</em></strong> modules. To know more about python modules you can check on python documentation <a target="_blank" href="https://docs.python.org/3/py-modindex.html">page</a>.</p>
<ol>
<li><h3 id="heading-math">Math</h3>
<p> The <strong>math</strong> module provides access to a variety of mathematical functions and constants.</p>
<ul>
<li><p><code>math.sqrt(x)</code>: Returns the square root of <code>x</code>.</p>
</li>
<li><p><code>math.pow(x, y)</code>: Returns <code>x</code> raised to the power of <code>y</code>.</p>
</li>
<li><p><code>math.pi</code>: The constant π (pi).</p>
</li>
<li><p><code>math.sin(x)</code>, <code>math.cos(x)</code>, <code>math.tan(x)</code>: Trigonometric functions.</p>
</li>
<li><p><code>math.log(x, base)</code>: Returns the logarithm of <code>x</code> to the specified <code>base</code>.</p>
<pre><code class="lang-python">  <span class="hljs-keyword">import</span> math
  print(math.sqrt(<span class="hljs-number">190</span>)     <span class="hljs-comment"># 13.784</span>
  print(<span class="hljs-string">"Value of pi:"</span>, math.pi) <span class="hljs-comment"># 3.1416</span>
</code></pre>
</li>
</ul>
</li>
</ol>
<ol start="2">
<li><h3 id="heading-keywords">Keywords</h3>
<p> <strong>Keyword</strong> module provides a simple way to check for Python keywords, which are reserved words that cannot be used as identifiers (variable names, function name etc.</p>
<pre><code class="lang-python"> <span class="hljs-keyword">import</span> keyword
 print(<span class="hljs-string">'Total keyword in python: '</span>, len(keyword.kwlist)) <span class="hljs-comment"># 35</span>
 print(keyword.kwlist)
 <span class="hljs-comment"># ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']</span>
</code></pre>
</li>
<li><h3 id="heading-random">Random</h3>
<p> The <strong>random</strong> module is used to generate random numbers and perform random operations. It is useful for tasks like simulations, gaming, and random sampling.</p>
<ul>
<li><p><code>random.random()</code>: Returns a random float between 0.0 and 1.0.</p>
</li>
<li><p><code>random.randint(a, b)</code>: Returns a random integer between <code>a</code> and <code>b</code> (inclusive).</p>
</li>
<li><p><code>random.shuffle(seq)</code>: Shuffles the sequence <code>seq</code> in place.</p>
<pre><code class="lang-python">  <span class="hljs-keyword">import</span> random
  print(random.randint(<span class="hljs-number">1</span>,<span class="hljs-number">100</span>)) <span class="hljs-comment"># 3</span>
  numbers = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>]
  random.shuffle(numbers)
  print(numbers)     <span class="hljs-comment"># [1,2,5,3,4]</span>
</code></pre>
</li>
</ul>
</li>
</ol>
<ol start="4">
<li><h3 id="heading-datetime">Datetime</h3>
<p> The <strong>datetime</strong> module supplies classes for manipulating dates and times. It is useful for applications that require date and time calculations.</p>
<ul>
<li><p><a target="_blank" href="http://datetime.date"><code>datetime.date</code></a><code>(y, m, d)</code>: Represents a date.</p>
</li>
<li><p><code>datetime.time(hrs, min, sec)</code>: Represents a time.</p>
</li>
<li><p><code>datetime.datetime(year, month, day, hour, minute, second)</code>: Represents both date and time.</p>
</li>
<li><p><a target="_blank" href="http://datetime.datetime.now"><code>datetime.datetime.now</code></a><code>()</code>: Returns the current local date and time.</p>
<pre><code class="lang-python">  <span class="hljs-keyword">import</span> datetime
  print(datetime.datetime.now())
  <span class="hljs-comment"># 2024-05-23 12:29:11.942735</span>
</code></pre>
</li>
</ul>
</li>
</ol>
<p>    <strong><mark>Task:</mark></strong></p>
<ol>
<li><p><code>Write a Python program that checks if a given word is a Python keyword.</code></p>
</li>
<li><p><code>Write a Python program that generates and prints a random password. The password should be 8 characters long and can include uppercase letters, lowercase letters, and digits.</code></p>
</li>
</ol>
<hr />
<h2 id="heading-loops">Loops</h2>
<p>Python provides two types of loops: <strong>for</strong> loops and <strong>while</strong> loops. In this section, we'll explore both types of loops,</p>
<ol>
<li><h3 id="heading-for-loop">For loop</h3>
<p> A <strong>for</strong> loop is used to iterate over a sequence (like a list, tuple, dictionary, set, or string) and execute a block of code for each item in the sequence.</p>
<pre><code class="lang-python">  <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>):
      print(i)
  <span class="hljs-comment"># 1</span>
  <span class="hljs-comment"># 2</span>
  <span class="hljs-comment"># 3</span>
  <span class="hljs-comment"># 4</span>
  <span class="hljs-comment"># 5</span>
 <span class="hljs-comment"># range() is often used to generate a sequence of numbers.</span>
</code></pre>
</li>
<li><h3 id="heading-while-loop">While loop</h3>
<p> A <strong>while</strong> loop executes a block of code as long as a specified condition is true.</p>
<pre><code class="lang-python"> i = <span class="hljs-number">1</span>
 <span class="hljs-keyword">while</span> i &lt;= <span class="hljs-number">4</span>:
     print(i)
     i += <span class="hljs-number">1</span>
 <span class="hljs-comment"># 1 </span>
 <span class="hljs-comment"># 2</span>
 <span class="hljs-comment"># 3</span>
 <span class="hljs-comment"># 4</span>
</code></pre>
<p> Above, <strong>while</strong> loop continues to execute as long as <code>i</code> is less than or equal to 4. The value of <code>i</code> is incremented by 1 in each iteration until the condition is no longer satisfied.</p>
</li>
</ol>
<p><strong><mark>Task:</mark></strong></p>
<ol>
<li><p><code>Write a Python program that takes an integer n as input and prints the multiplication table for n up to 10.</code></p>
</li>
<li><p><code>The current population of a town is 10000. The population of the town is increasing at the rate of 10% per year. You have to write a program to find out the population at the end of each of the last 10 years.</code></p>
</li>
</ol>
<hr />
<p><em>If you have any questions on any topic covered in this blog post, feel free to leave a comment below. I'm here to help you on your learning journey!</em></p>
<p><em>Happy coding and happy learning! 🚀</em></p>
]]></content:encoded></item><item><title><![CDATA[Session 1 - Python Fundamentals]]></title><description><![CDATA[Python is a programming language that has become very famous in recent years. It is powerful, flexible, and easy to learn. Since it was first released in 1991 by Guido van Rossum, Python has been a great choice for both new and experienced coders bec...]]></description><link>https://pdlmanoj.com.np/session-1-python-fundamentals</link><guid isPermaLink="true">https://pdlmanoj.com.np/session-1-python-fundamentals</guid><category><![CDATA[python beginner]]></category><category><![CDATA[Basics of Python]]></category><category><![CDATA[Practice coding]]></category><dc:creator><![CDATA[Manoj Paudel]]></dc:creator><pubDate>Thu, 16 May 2024 18:15:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/ZIPFteu-R8k/upload/ff955e6f4b962509531b221d394dea1d.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Python</strong> is a programming language that has become very famous in recent years. It is powerful, flexible, and easy to learn. Since it was first released in 1991 by Guido van Rossum, Python has been a great choice for both new and experienced coders because it focuses on making code easy to read and simple.</p>
<p><img src="https://ladmerc.files.wordpress.com/2015/05/learn-python.jpg" alt="learning Python | Ladna's Blog" class="image--center mx-auto" /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">🧐</div>
<div data-node-type="callout-text"><strong>Why learn python for Data Science?</strong></div>
</div>

<ol>
<li><p><strong>Powerful Libraries</strong>: Tools like NumPy, Pandas, Matplotlib, and Scikit-Learn simplify data analysis, manipulation, visualization, and machine learning.</p>
</li>
<li><p><strong>Community and Resources</strong>: A large, active community and abundant resources (tutorials, courses, documentation) provide ample learning support.</p>
</li>
<li><p><strong>Versatility</strong>: Python integrates well with other technologies and is used across various fields, making it a flexible tool.</p>
</li>
<li><p><strong>Industry Demand</strong>: Many top companies use Python for data science, enhancing job prospects and career opportunities.</p>
</li>
</ol>
<hr />
<ol>
<li><h3 id="heading-python-output">Python Output</h3>
</li>
</ol>
<pre><code class="lang-python">print(<span class="hljs-string">'Hello World'</span>)
<span class="hljs-comment">#Output: Hello World</span>
print(<span class="hljs-string">'Hello'</span>, <span class="hljs-number">1</span>, <span class="hljs-number">4.5</span>, <span class="hljs-literal">True</span>) <span class="hljs-comment"># multiple item print</span>
<span class="hljs-comment">#Output: Hello 1 4.5 True</span>
print(<span class="hljs-string">'Hello'</span>, <span class="hljs-number">1</span>, <span class="hljs-number">4.5</span>, <span class="hljs-literal">True</span>, sep = <span class="hljs-string">'/'</span>) <span class="hljs-comment"># each item seperated by /</span>
<span class="hljs-comment">#Output: Hello/1/4.5/True</span>
print(<span class="hljs-string">'Hello'</span>, end = <span class="hljs-string">'-'</span>) <span class="hljs-comment"># Default newline </span>
print(<span class="hljs-string">'World'</span>)
<span class="hljs-comment">#Output: Hello-World</span>
</code></pre>
<p><strong>Remember</strong>, python is <strong>case-sensitive</strong> language means is <em>Print() and print()</em> are not same.</p>
<hr />
<ol start="2">
<li><h3 id="heading-data-type">Data Type</h3>
<p> In every programming language data type are important, <em>python has integer, float, boolean, string, complex, list, tuple, sets, dictionary.</em></p>
</li>
</ol>
<pre><code class="lang-python"><span class="hljs-comment"># Integer </span>
print(<span class="hljs-number">8</span>)
print(<span class="hljs-number">1e308</span>) <span class="hljs-comment"># handel till 1* 10 ^ 308 integers</span>
<span class="hljs-comment">#Float</span>
print(<span class="hljs-number">23.3</span>)
print(<span class="hljs-number">1.7e308</span>) <span class="hljs-comment"># handel till 1 * 10 ^ 308 floats</span>
<span class="hljs-comment"># Boolean </span>
<span class="hljs-comment"># True | False</span>
print(<span class="hljs-literal">True</span>)
<span class="hljs-comment"># String</span>
print(<span class="hljs-string">'Hey I am a string'</span>)
<span class="hljs-comment"># <span class="hljs-doctag">NOTE:</span> Python doesn't have char dtype only string</span>
<span class="hljs-comment"># Complex</span>
print(<span class="hljs-number">5</span>+<span class="hljs-number">6j</span>)

<span class="hljs-comment">#Output:   </span>
<span class="hljs-comment">#   8</span>
<span class="hljs-comment">#   inf</span>
<span class="hljs-comment">#    23.3</span>
<span class="hljs-comment">#   inf</span>
<span class="hljs-comment">#  True</span>
<span class="hljs-comment">#    Hey I am a string</span>
<span class="hljs-comment">#   (5+6j)</span>
</code></pre>
<pre><code class="lang-python"><span class="hljs-comment"># List</span>
print([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>])
<span class="hljs-comment"># Tuple</span>
print(<span class="hljs-number">12</span>,<span class="hljs-number">13</span>,<span class="hljs-number">14</span>,<span class="hljs-number">15</span>)
<span class="hljs-comment"># Dictionary</span>
print({Fruit: <span class="hljs-string">'Apple'</span>, Name: <span class="hljs-string">'Beta'</span>}
<span class="hljs-comment"># Set</span>
print({<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>})

<span class="hljs-comment">#Output: </span>
<span class="hljs-comment">#   [1, 2, 3, 4, 5]</span>
<span class="hljs-comment">#   12 13 14 15</span>
<span class="hljs-comment">#   {'name': 'Ninja', 'gender': 'Male', 'weight': 60}</span>
<span class="hljs-comment">#   {1, 2, 3, 4, 5}</span>
</code></pre>
<ol start="3">
<li><h3 id="heading-variables">Variables</h3>
<p> <strong>Variables</strong> in python on the other hand, are like labeled containers that store any kind of information. For eg: You are a web developer and want to show login user name after s/he login-in successfully [ Hello, [var_name] ] for this, you just define a variable name and as user login in you pass that name to var_name . So, in simple term variables are container for future use.</p>
<pre><code class="lang-python"> name = <span class="hljs-string">'myName'</span>
 print(name)
 <span class="hljs-comment"># No need to explicitly declear dtype it automatically know</span>

 a = <span class="hljs-number">5</span>
 b = <span class="hljs-number">6</span>
 print(a + b) <span class="hljs-comment"># Output: 11</span>

 <span class="hljs-comment"># In python, variable don't need to declear at the top like C/ C++, </span>
 <span class="hljs-comment"># as you need you declear it.</span>
</code></pre>
 <div data-node-type="callout">
 <div data-node-type="callout-emoji">❓</div>
 <div data-node-type="callout-text"><strong>Interview Question:</strong></div>
 </div>

<blockquote>
<p><strong>1. Difference between Dynamic vs Static Typing?</strong></p>
<p>- In dynamic, you explicitly tell data-type while declaring variable.</p>
<p>Eg. int a = 5; [ C/ C++/ Java]</p>
<p>- In static, you don't need to declare data-type, interpreter automatically know. Eg. a = 5</p>
<hr />
<p><strong>2. Difference between Dynamic vs Static Binding?</strong></p>
<p>- In dynamic binding, variable you created doesn't have fixed data-type meaning we can change it's data-type as need.</p>
<p><em>Eg. a = 5 | a = 'apple'</em> ✅</p>
<p>- In static binding, once you define a variable data-type then it's fixed you can't change its data-type.</p>
<p><em>Eg. int num = 50 | string num = 'hello' ❌</em></p>
</blockquote>
<hr />
</li>
<li><h3 id="heading-keywords-and-identifiers">Keywords and Identifiers</h3>
<p> Simply, <strong>keyword</strong> are the reserved word which are predefined in python and have special meanings to the compiler. We cannot use this <em>36 keywords</em> as variable name, function name in python.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715765044396/d15fda5d-f59d-46df-a22b-1a53f34b97f6.png" alt class="image--center mx-auto" /></p>
<p> <strong>Identifiers</strong> are the names given by programmer to variables, functions, classes. There are some rules we need to follow to create a valid identifiers.</p>
</li>
</ol>
<ul>
<li><p>You can't start name with a digit. <code>1name = 'myName' ❌</code></p>
</li>
<li><p>You cannot use any special character except underscore <code>_</code></p>
<p>  <code>first_name = 'John'</code> ✅</p>
<p>  <em>Any other than underscore</em><code>_</code><em>are not valid to create an identifiers.</em></p>
</li>
<li><p>Identifiers cannot be keywords</p>
</li>
</ul>
<hr />
<ol start="5">
<li><h3 id="heading-user-input">User Input</h3>
<p> Taking input from user is important as a programmer. There are two type of software: <strong><em>static</em></strong> and <strong><em>dynamic software</em></strong>. <strong>Static software</strong> are those software which do not interact with user (only provide information). For eg: clock, calendar, a blog, college website (mostly static). <strong>Dynamic software</strong> is where user interact with software (input). For eg: Youtube, booking ride, placing food order and so on. In today's world, almost 90 % of software are dynamic software.</p>
<p> To make, such dynamic software, we need to take input from the user first.</p>
</li>
</ol>
<pre><code class="lang-python"><span class="hljs-comment"># Taking input from user and store in user_name variable</span>
user_name = input(<span class="hljs-string">"Enter your name:"</span>)
print(<span class="hljs-string">"Hello, {0}! How are you?"</span>.format(user_name))

<span class="hljs-comment"># Output: </span>
<span class="hljs-comment"># Enter your name: rajesh</span>
<span class="hljs-comment"># Hello, rajesh! How are you?</span>
</code></pre>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><strong>Advice:</strong> To write code effectively, you should first in your mind think on the problem what exact step you gonna follow, then you should code line by line.</div>
</div>

<p><strong>Task :</strong><code>Write a program to take 2 numbers from user and print sum of two numbers.</code></p>
<hr />
<ol start="6">
<li><h3 id="heading-type-conversion">Type Conversion</h3>
<p> In python, we have two type conversion, <em>implicit and explicit.</em> In <em>implicit</em> type conversion, compiler internally convert the type with programmer interaction. But, implicit doesn't work all the time. Whereas, <em>explicit</em> type conversion, programmer change the type of data manually.</p>
</li>
</ol>
<pre><code class="lang-python"><span class="hljs-comment"># Implicit</span>
print(<span class="hljs-number">5</span>+<span class="hljs-number">6.6</span>)        <span class="hljs-comment"># 11.6</span>
print(type(<span class="hljs-number">5</span>),type(<span class="hljs-number">5.6</span>))     <span class="hljs-comment"># &lt;class 'int'&gt; &lt;class 'float'&gt;   </span>
<span class="hljs-comment">## Python automatically convert the type but may not work always.</span>

print(<span class="hljs-number">4</span> + <span class="hljs-string">'4'</span>)     <span class="hljs-comment"># Error</span>
</code></pre>
<pre><code class="lang-python"><span class="hljs-comment"># Explicit</span>
<span class="hljs-comment"># string to integer</span>
type(int(<span class="hljs-string">'4'</span>))    <span class="hljs-comment"># int</span>
int(<span class="hljs-number">4.5</span>)     <span class="hljs-comment"># 4</span>
int(<span class="hljs-number">4</span>+<span class="hljs-number">5j</span>)    <span class="hljs-comment"># Error [can't convert complex to integer]</span>
<span class="hljs-comment">#### So, type conversion only work when possible.</span>

str(<span class="hljs-number">5</span>)     <span class="hljs-comment"># '5'</span>
float(<span class="hljs-number">6</span>)     <span class="hljs-comment"># 6.0</span>
</code></pre>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><strong>Remember: </strong>InPython, type conversion doesn't change the type of original data, instead it create a new copy value where type conversion operation take place.</div>
</div>

<hr />
<ol start="7">
<li><h3 id="heading-literals">Literals</h3>
<p> <strong>Literals</strong> are the raw values that you store in variable. There are many way to set literals in python we will look on them one by one.</p>
<p> <img src="https://almablog-media.s3.ap-south-1.amazonaws.com/Frame_10_min_e9d8b9183e.png" alt="Literals in Python Example" /></p>
<pre><code class="lang-python"> a = <span class="hljs-number">0b1010</span> <span class="hljs-comment"># Binary Literals</span>
 b = <span class="hljs-number">100</span> <span class="hljs-comment"># Decimal Literal</span>
 c = <span class="hljs-number">0o310</span> <span class="hljs-comment"># Octal Literal</span>
 d = <span class="hljs-number">0x12c</span> <span class="hljs-comment"># Hexadecimal Literal</span>

 <span class="hljs-comment"># Float Literal</span>
 float_1 = <span class="hljs-number">10.5</span>
 float_2 = <span class="hljs-number">1.5e2</span> <span class="hljs-comment"># 1.5 * 10^2</span>
 float_3 = <span class="hljs-number">1.5e-3</span> <span class="hljs-comment"># 1.5 * 10^-3</span>

 <span class="hljs-comment"># Complex Literal</span>
 x = <span class="hljs-number">3.14j</span>

 print(a, b, c, d) <span class="hljs-comment"># 10 100 200 300</span>
 print(float_1, float_2,float_3) <span class="hljs-comment"># 10.5 150.0 0.0015</span>
 print(x, x.imag, x.real) <span class="hljs-comment"># 3.14j 3.14 0.0</span>
</code></pre>
<p> <strong>Moreover,</strong> in python we can store unicode (emojis) and raw strings.</p>
</li>
</ol>
<pre><code class="lang-python">unicode = <span class="hljs-string">u"\U0001f600\U0001F606\U0001F923"</span>
raw_str = <span class="hljs-string">r"raw \n string"</span>

print(unicode)    <span class="hljs-comment"># 😀😆🤣</span>
print(raw_str)    <span class="hljs-comment"># raw \n string</span>
</code></pre>
<pre><code class="lang-python"><span class="hljs-comment"># In python, boolean True (1) and False (0) treated as a number</span>
<span class="hljs-comment"># So, we can do as follows,</span>

a = <span class="hljs-literal">True</span> + <span class="hljs-number">4</span>
b = <span class="hljs-literal">False</span> + <span class="hljs-number">10</span>

print(a)    <span class="hljs-comment"># 5</span>
print(b)    <span class="hljs-comment"># 10</span>
</code></pre>
<h3 id="heading-none-literals"><strong>None Literals</strong></h3>
<p>In python like other programming we cannot declare variable beforehand. To do so, we can used <strong>None</strong> (a variable with no value).</p>
<pre><code class="lang-python">k <span class="hljs-comment"># error can't do</span>
a = <span class="hljs-literal">None</span> <span class="hljs-comment"># use None to clear no value variable</span>
print(a) <span class="hljs-comment"># None</span>
</code></pre>
<hr />
<ol start="8">
<li><h3 id="heading-practice-question"><strong>Practice Question</strong></h3>
<p> <code>1. WAP that will convert celsius value to Fahrenheit.</code></p>
<p> <code>2. WAP to take 2 numbers from user and swap them without using any special python syntax.</code></p>
<p> <code>3. WAP to find the sum of squares of first n natural numbers where n will be provided by the user.</code></p>
<p> <code>4. Given the first 2 terms of an Arithmetic Series. Find the Nth term of the series. Just assume all inputs are provided by user.</code></p>
</li>
</ol>
<p><strong>Happy Coding! 🧑🏻‍💻</strong></p>
]]></content:encoded></item></channel></rss>