<?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: Evans Mutwiri</title>
    <description>The latest articles on DEV Community by Evans Mutwiri (@evansmutwiri).</description>
    <link>https://dev.to/evansmutwiri</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%2F810973%2Ff146427e-a895-46f9-8dc0-524e7751bf15.png</url>
      <title>DEV Community: Evans Mutwiri</title>
      <link>https://dev.to/evansmutwiri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/evansmutwiri"/>
    <language>en</language>
    <item>
      <title>Reactive programming in Android</title>
      <dc:creator>Evans Mutwiri</dc:creator>
      <pubDate>Tue, 14 Jan 2025 11:46:31 +0000</pubDate>
      <link>https://dev.to/evansmutwiri/reactive-programming-in-android-49e</link>
      <guid>https://dev.to/evansmutwiri/reactive-programming-in-android-49e</guid>
      <description>&lt;p&gt;I am learning a rather huge code base and.... well.&lt;/p&gt;

&lt;p&gt;Reactive programming is a design paradigm that handles real-time updates to otherwise static content using asynchronous programming logic. It provides an efficient method for handling data updates to content whenever a user makes an inquiry (via automated data streams).&lt;/p&gt;

&lt;h2&gt;
  
  
  Imperative vs Reactive
&lt;/h2&gt;

&lt;p&gt;Reactive programming is declarative as opposed to imperative. &lt;br&gt;
Imperative programming is programming "how to do something"&lt;/p&gt;

&lt;h3&gt;
  
  
  Imperative example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val result = mutableListOf&amp;lt;Int&amp;gt;()

    for (i in 1..5) {
        result.add(i)
    }

    println("result is $result")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Reactive example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    val result = (1..5).map { it }

    println("Declaritive result $result")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the examples, if imperative programming is food recipe, then reactive programming is ordering food!&lt;/p&gt;

&lt;h2&gt;
  
  
  Kotlin collections api
&lt;/h2&gt;

&lt;p&gt;Kotlin collections api makes reactive programming easy as knowledge of the existence. There are about 200 of them.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://jussi.hallila.com/Kollections/" rel="noopener noreferrer"&gt;Cheatsheet&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Introduction to Data Structures and Algorithms With Python</title>
      <dc:creator>Evans Mutwiri</dc:creator>
      <pubDate>Mon, 21 Feb 2022 20:54:44 +0000</pubDate>
      <link>https://dev.to/evansmutwiri/introduction-to-data-structures-and-algorithms-with-python-40mi</link>
      <guid>https://dev.to/evansmutwiri/introduction-to-data-structures-and-algorithms-with-python-40mi</guid>
      <description>&lt;p&gt;This post will help you guys understand the fundamentals of data structures and algorithms.&lt;/p&gt;

&lt;p&gt;Data is bits of information. We store them so we can use them later. It’s like putting clothes in a drawer. The drawer is the data structure.&lt;/p&gt;

&lt;p&gt;Data structures are a way of storing and organizing data efficiently. This will allow you to easily access and perform operations on the data. They define the relationship between the data, and the operations that can be performed on the data. &lt;br&gt;
This defination will guide the approach of this post to make us understand data structures better and to work with the more effectively using Python.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Data Structures in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;They can be mainly classified into two types as shown in this diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QxfTgKNz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2019/10/TreeStructure-Data-Structures-in-Python-Edureka1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QxfTgKNz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2019/10/TreeStructure-Data-Structures-in-Python-Edureka1.png" alt="Screenshot" width="880" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;TL,DR:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Python Built-in data structures: These are the data structures that come along with Python and can be implemented same as primitive data types like integers, etc. These can be further classified into:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;a. Lists&lt;br&gt;
b. Sets&lt;br&gt;
c. Tuples&lt;br&gt;
d. Dictionaries&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Python User-defined data structures: These data structures are the ones built using the built-in data structures and have their own properties. Based on these features, these are used in suitable situations. These can be subdivided into:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;a. Stacks&lt;br&gt;
b. Queues&lt;br&gt;
c. Linked Lists&lt;br&gt;
d. Hash Maps&lt;br&gt;
e. Trees&lt;br&gt;
f. Graphs&lt;/p&gt;

&lt;p&gt;Having known the types, we will define a data structure and work with each in detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Structure #1: Lists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements. &lt;br&gt;
Lists are among the 4 built in data structures in Python, used to store collections of data.&lt;br&gt;
Just as strings are defined as characters between quotes, lists are defined by having values between square brackets [ ].&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;droids = ['C-3P0', 'IG-88', 'R2-D2', 'R5-4', 'BB-8']

print(droids)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Output: ['C-3P0', 'IG-88', 'R2-D2', 'R5-4', 'BB-8']&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Each element or value that is inside of a list is called an item. Items in a list are separated using a comma. List items are indexed, the first item has index [0], the second item has index [1] etc. &lt;/p&gt;

&lt;p&gt;We can call a specific droid(a item of the list) by referring to its index number:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;droids[0] = 'C-3P0'&lt;br&gt;
droids[1] = 'IG-88'                                &lt;br&gt;
droids[2] = 'R2-D2'                                                  &lt;br&gt;
droids[3] = 'R5-4'                                                    &lt;br&gt;
droids[4] = 'BB-8'&lt;/code&gt;&lt;br&gt;&lt;br&gt;
If we call an index number greater than 4 say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(droids[6])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the program will throw an error because the index number is out of bounds.&lt;br&gt;
&lt;code&gt;Output: IndexError: list index out of range&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;List items can also be accessed using negative indexes. For instance &lt;code&gt;droids[-1]&lt;/code&gt; can be used to access the last item in a list and so on till the first item.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(droids[-3])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Output: R2-D2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;List items are ordered, changeable, and allow duplicate values. When we say lists are ordered, it means that the items have a defined order, and that order will not change. If you add new items to a list, the new items will be placed at the end of the list.&lt;/p&gt;

&lt;p&gt;Lists let you save lots of things in a single variable. A list can be of any data type, and can contain different data types. A list can store numbers, booleans or even other lists! Since lists are indexed they allow duplicate values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["apple", "banana", "cherry", "apple", "cherry"]
print(fruits)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To determine the number of items a list has, use the len() function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print (len(fruits))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Output: 4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can definetly do alot more with lists using &lt;a href="https://www.python-ds.com/python-3-list-methods"&gt;list methods and functions available in Python 3.&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Structure #2: Tuples in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tuples are used to store multiple items in a single variable. Just like a list it is also a sequence data type capable of containing elements of multiple data types. In other words, a tuple refers to a collection of various objects(items) that stay separated by commas, and enclosed in rounded brackets(). A tuple is comparatively much faster than a list because it is static in nature.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits_tuple = ("apple", "banana", "cherry")
print(fruits_tuple)

fruits_tuple = tuple(("apple", "banana", "cherry")) # note the double round-brackets
print(fruits_tuple)

// brackets are actually optional
weekdays = "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"
print(weekdays)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;("apple", "banana", "cherry")

("apple", "banana", "cherry")

("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If, for some reason, you need to create a tuple with a single item, you need to include a comma, otherwise you'll end up with a string.&lt;/p&gt;

&lt;p&gt;They differ from lists in a number of ways as shown in the figure below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_SKbUt4G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwtu275zxalop1cdv6nl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_SKbUt4G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwtu275zxalop1cdv6nl.png" alt="Lists vs Tuple" width="704" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tuples are used to pass arguments and return results from functions. This is because they can contain multiple elements and are immutable. &lt;br&gt;
Tuples are also good for storing closely related data. For example, (x, y, z) coordinates or (r, g, b) colour components can be stored as tuples. &lt;br&gt;
Tuple values cannot be modified.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fruits_tuple[0] = 'mango'&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

&amp;lt;ipython-input-74-b5d6da8c1297&amp;gt; in &amp;lt;module&amp;gt;()
----&amp;gt; 1 fruits_tuple[0] = 0 # Cannot change values inside a tuple


TypeError: 'tuple' object does not support item assignment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can actually make changes to a tuple by converting it to a list using list(). And when you are done making the changes, you can again convert it back to a tuple using tuple().&lt;/p&gt;

&lt;p&gt;This change, is resource expensive as it involves making a copy of the tuple. Use lists instead if values can change during the lifetime of the object.&lt;/p&gt;

&lt;p&gt;To append the values, you use the ‘+’ operator which will take another tuple to be appended to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_tuple = (1, 2, 3)
my_tuple = my_tuple + (4, 5, 6) #add elements
print(my_tuple)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Output: (1, 2, 3, 4, 5, 6)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Structure #3: Dictionary in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Python, a dictionary is an ordered* collection of items, with each item consisting of a key: value pair (separated by a colon). Dictionaries changeable and do not allow duplicates.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;As of Python version 3.7, dictionaries are ordered. In Python 3.6 and earlier, dictionaries are unordered.&lt;a href="https://www.w3schools.com/python/python_dictionaries.asp"&gt;Ref&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A Dictionary is created by placing a sequence of elements within curly &lt;strong&gt;{}&lt;/strong&gt; braces, separated by &lt;strong&gt;‘comma’&lt;/strong&gt;. Dictionary holds &lt;strong&gt;pairs of values&lt;/strong&gt;, one being the &lt;strong&gt;Key&lt;/strong&gt; and the other corresponding pair element being its &lt;strong&gt;Key:value&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;d = {"Key1": "Value1", "Key2": "Value2"}
print(d)
print(type(d))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"Key1": "Value1", "Key2": "Value2"}
&amp;lt;class 'dict'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another way of creating a dictionary is with the &lt;code&gt;dict()&lt;/code&gt; function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;d = dict({"Key1": "Value1", "Key2": "Value2"})
d = dict(Key1: Value1, Key2: Value2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are a few important things to note when creating dictionaries in Python:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Each key should be unique. Dictionaries do not support duplicate keys. They are however case sentive so similar keys written in different cases will be treated as different keys.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keys are immutable. That means you can use a data type that can't be changed such as strings, numbers, or even tuples as keys, but you can't use lists, or other dictionaries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;These restrictions only apply only on keys not values.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>python</category>
      <category>algorithms</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Python 101: The Basics</title>
      <dc:creator>Evans Mutwiri</dc:creator>
      <pubDate>Sun, 13 Feb 2022 06:35:34 +0000</pubDate>
      <link>https://dev.to/evansmutwiri/python-101-the-basics-57in</link>
      <guid>https://dev.to/evansmutwiri/python-101-the-basics-57in</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
To get the best out of this article you should be familiar with the following concepts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Python as a programming language , programming techniques supported python programming language and it’s programming language category.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Variables, defining and using variables in python programming language. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Comments, keywords, identifiers, rules to follow when defining identifiers  literals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Built-in functions in python programming language like print( … )&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Operators in python programming language.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://pep8.org/" rel="noopener noreferrer"&gt;PE8 rules and standards&lt;/a&gt; in Python programming language.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Control flow and decision making in Python
&lt;/h2&gt;

&lt;p&gt;Conditional statements are also known as decision-making statements. We need to use these conditional statements to execute the specific block of code if the given condition is true or false.&lt;/p&gt;

&lt;p&gt;In Python we can achieve this using:&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;#1) -&lt;u&gt;if else statements&lt;/u&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;It checks whether a condition is true or not. If the condition is true the code inside the "if" block is executed otherwise it's not. Else block provide an alternative code to be executed if the first is not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If ( CONDITION == TRUE ):
     Block to execute
else:
     Block to execute otherwise
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see and discuss some examples of if statements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print('Example: 1')

num = 5

if (num &amp;lt; 10):
    print('Num is smaller than 10')
else:
    print('Num is not smaller than 10')


print('Example: 2')

a = 7
b = 0

if(a):
    print('true')
else:
    print('false')

print('Example: 3')

if('python' in ['Java', 'Python', 'Dart']):
    print('Python found in the List')
else:
    print('Python not found')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;em&gt;Example 1&lt;/em&gt; we check the statement whether our variable is less than 10. If the statement is true the print method following it is executed.&lt;br&gt;
&lt;em&gt;Remember to use the (:) operator at the end of the if statement, because whatever the code you write after the colon operator will be a part of “if block” and indentation is very important.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In &lt;em&gt;Example 2&lt;/em&gt;, we are not looking for any condition. In any programming language, a positive number is considered a true value so our program produced output 'true'.&lt;/p&gt;

&lt;p&gt;In &lt;em&gt;Example 3&lt;/em&gt; we check the list of languages to check whether Python is in it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Example 4
passing_Mark = 60
my_Score = 67
if(my_Score &amp;gt;= passing_Score):
    print('Congratulations! You passed the exam')
    print("You are passed in the exam")        
else:
    print('Sorry! You failed the exam, better luck next time')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh45ibrd34mr3m5uveoj6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh45ibrd34mr3m5uveoj6.png" alt="Example 4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;#2) -&lt;u&gt;elif statements&lt;/u&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;"elif" statement is used to check multiple conditions only if the given condition is false. The difference between elif and else statements is that elif checks for a condition while else does not check for a condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (condition):
    #Set of statement to execute if condition is true
elif (condition):
    #Set of statements to be executed when if condition is false and elif condition is true
else:
    #Set of statement to be executed when both if and elif conditions are false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Example of elif statement

num = int(input("Enter number: "))
if (num &amp;gt; 0):
    print('Number is positive')
elif (num &amp;lt; 0):
    print('Number is negative')
else:
    print('Number is Zero')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example we try something new by taking user input. By default the input is a string so we have to type cast it to integer to perform the operation.&lt;br&gt;
The program will check if num is greater than 0(condition),&lt;br&gt;
if not we check the condition in elif(num is less than 0),&lt;br&gt;
if both are not true only then is the else statement reached.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;Python if statement evaluates a boolean expression to true or false, if the condition is true then the statement inside the if block will be executed in case the condition is false then the statement present inside the else block will be executed only if you have written the else block otherwise it will do nothing.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Python Loops – For, While&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In Python, statements are executed in a sequential manner ie. one line after another. However, you may want to repeat some lines until a certain condition is met. That's where loops come through for you.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>Python 101: Ultimate Python Guide</title>
      <dc:creator>Evans Mutwiri</dc:creator>
      <pubDate>Fri, 11 Feb 2022 12:26:54 +0000</pubDate>
      <link>https://dev.to/evansmutwiri/python-101-getting-started-lje</link>
      <guid>https://dev.to/evansmutwiri/python-101-getting-started-lje</guid>
      <description>&lt;h2&gt;
  
  
  Why Python?
&lt;/h2&gt;

&lt;p&gt;Python is a clear and powerful interpreted, general purpose, object-oriented programming language with classes and multiple inheritances. Python is a dynamically typed and garbage collected language. Why dynamic? We don't have to declare the type of a variable while assigning a value to a variable in Python.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A variety of basic data types are available: numbers (floating point, complex, and unlimited-length long integers), strings, lists, and dictionaries. &lt;/li&gt;
&lt;li&gt;Clean error handling&lt;/li&gt;
&lt;li&gt;Memory management, involving a private heap containing all Python objects and data structures.&lt;/li&gt;
&lt;li&gt;Python uses an elegant syntax, making the programs you write easier to read, easy to test and it runs anywhere, including Mac OS X, Windows, Linux and Unix.&lt;/li&gt;
&lt;li&gt;Python is free to use and is available under open source.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use cases:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Python is a multipurpose programming language. You can use Python for, but not limited to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Machine learning and AI. Python is the number 1 programming language for machine learning and data science.&lt;/li&gt;
&lt;li&gt;Web development.Using Python and a framework called Django.&lt;/li&gt;
&lt;li&gt;Automation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Setting up&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need to install Python 3 interpreter in your computer. This will read and execute our Python programs. Python 3.10 is the latest version with the latest features. This article uses Python 3.8 (which is the latest security release), in the &lt;a href="https://docs.conda.io/en/latest/"&gt;conda&lt;/a&gt; environment.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Read more about setting up the environment&lt;/strong&gt;&lt;/em&gt; &lt;a href="https://wiki.python.org/moin/BeginnersGuide/Download"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Hello World!
&lt;/h3&gt;

&lt;p&gt;Whatever your reason for learning Python is, it's possible. We shall kick off the journey with our first app.&lt;br&gt;
&lt;strong&gt;Run python&lt;/strong&gt;&lt;br&gt;
Once the installation is complete you can run python.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Running Python in the terminal&lt;/strong&gt; by typing &lt;code&gt;python&lt;/code&gt; and writing python code next.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eazzy@eazzy-HP-ProDesk-400-G3-MT:~$ conda activate my_env
(my_env) eazzy@eazzy-HP-ProDesk-400-G3-MT:~$ python
Python 3.8.12 (default, Oct 12 2021, 13:49:34) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
&amp;gt;&amp;gt;&amp;gt; print('hello world')
hello world
&amp;gt;&amp;gt;&amp;gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Type &lt;code&gt;quit()&lt;/code&gt; to exit python if you wish to.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run Python in Integrated Development Environment (IDE)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Prerequisites&lt;/p&gt;

&lt;p&gt;Specifically, we require:&lt;br&gt;
&lt;a href="https://code.visualstudio.com/Download"&gt;VS Code&lt;/a&gt;&lt;br&gt;
VS Code &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-python.python"&gt;Python extension&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create an empty directory called &lt;code&gt;hello&lt;/code&gt; In it we will create our python file. A python file file has a .py extension. Open in vs-code.&lt;br&gt;
From the File Explorer toolbar, select the New File button on the hello folder. Name the file &lt;code&gt;hello.py&lt;/code&gt;, and it automatically opens in the editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;msg = "Hello World"
print(msg)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Click the Run Python File in Terminal play button in the top-right side of the editor.&lt;br&gt;
You will get the following output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4-rLHmI6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bhhq5ca61qsw3d8kqvxz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4-rLHmI6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bhhq5ca61qsw3d8kqvxz.png" alt="vs code screen grab" width="880" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy dance! We just wrote our first program in Python.&lt;/p&gt;

&lt;p&gt;There is then much more to explore with Python in Visual Studio Code.&lt;/p&gt;

&lt;p&gt;Next we shall learn about &lt;a href="https://dev.to/evansmutwiri/python-101-the-basics-57in"&gt;the basics of python.&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://wiki.python.org/moin/BeginnersGuide/Overview"&gt;Reference&lt;/a&gt;&lt;br&gt;
&lt;a href="https://wiki.python.org/moin/BeginnersGuide/NonProgrammers"&gt;BeginnersGuide&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.pythonchecker.com/"&gt;PythonChecker Makes Your Code Great Again&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
  </channel>
</rss>
