<?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: David-Gitonga</title>
    <description>The latest articles on DEV Community by David-Gitonga (@davidgitonga).</description>
    <link>https://dev.to/davidgitonga</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%2F815000%2F1fef42ec-0d04-48a6-b030-0fe32e85946a.png</url>
      <title>DEV Community: David-Gitonga</title>
      <link>https://dev.to/davidgitonga</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davidgitonga"/>
    <language>en</language>
    <item>
      <title>Introduction to modern python</title>
      <dc:creator>David-Gitonga</dc:creator>
      <pubDate>Fri, 22 Apr 2022 09:26:12 +0000</pubDate>
      <link>https://dev.to/davidgitonga/introduction-to-modern-python-1c7k</link>
      <guid>https://dev.to/davidgitonga/introduction-to-modern-python-1c7k</guid>
      <description>&lt;p&gt;Python is an interpreted, general, high-level programming language invented by Guido van Rossum and conceived in 1991.&lt;br&gt;
Python is a friendly, easy and simple language.&lt;/p&gt;
&lt;h1&gt;
  
  
  What makes python simple?
&lt;/h1&gt;

&lt;p&gt;It's syntax emphasizes readability thus it is very simple to read, write and understand the code.&lt;/p&gt;
&lt;h1&gt;
  
  
  Applications of python
&lt;/h1&gt;

&lt;p&gt;Web development&lt;br&gt;
Data science &lt;br&gt;
Machine learning and artificial intelligence&lt;br&gt;
Game development&lt;br&gt;
Desktop applications&lt;br&gt;
Automation&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Python installation&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Visit &lt;a href="https://www.python.org/downloads/%5B%5D(url)"&gt;https://www.python.org/downloads/[](url)&lt;/a&gt;&lt;br&gt;
Select your Operating system&lt;br&gt;
Select the release or version, click on it to download.&lt;br&gt;
Double click on the file to execute and install. For window mark "add to system paths" An alternative way to install python on Linux is to run &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;gt; sudo apt install python3&lt;/code&gt; or  &lt;code&gt;sudo apt install python on the terminal&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Variables in python&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;A variable is a pointer to an object. Once an object is assigned to a variable you refer to the object by that name. But the data itself is contained in the object. In python you don't have to declare the python before using them or declaring their type.&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;em&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;/em&gt;
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Values stored in variables can be changed during program execution.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A variable is only a name given to an object and all the operations done on the variable affect the object.&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Rules for creating variables.&lt;/strong&gt;
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Must start with a letter or underscore character.&lt;/li&gt;
&lt;li&gt;Variable cannot start with a number.&lt;/li&gt;
&lt;li&gt;Can only contain alpha-numeric character and underscore(A- 
Z,0-9, _)&lt;/li&gt;
&lt;li&gt;Variables are case sensitive, (age, Age and AGE) are 
different variables&lt;/li&gt;
&lt;li&gt;Keywords cannot be used to name variables.
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#declaring variables
age = 45
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h1&gt;
  
  
  Literals in python.
&lt;/h1&gt;

&lt;p&gt;This is data given in variables.&lt;br&gt;
 Python has different types of variables;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;String literals &lt;/li&gt;
&lt;li&gt;Numeric literals&lt;/li&gt;
&lt;li&gt;Boolean literals&lt;/li&gt;
&lt;li&gt;Literal collections&lt;/li&gt;
&lt;li&gt;Special literal&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;1.String literals&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;These are characters that are surrounded by single or double quotes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#In single quote
name = 'David'

#In double quotes
name = "David"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;2.Numeric literals&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;They are of different types;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Integers &lt;/li&gt;
&lt;li&gt;Float&lt;/li&gt;
&lt;li&gt;Complex&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. Integers&lt;/strong&gt;&lt;br&gt;
These are both positive and negative integers without floating point numbers.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Float&lt;/strong&gt; &lt;br&gt;
 These are both positive and negative numbers with &lt;br&gt;
 floating &lt;br&gt;
 point numbers(with decimals).&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Complex&lt;/strong&gt;&lt;br&gt;
   These are numbers having both a real and imaginary part in the form of x + 5j, where x is real and y is imaginary &lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;3. Boolean literals&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;They are only two;&lt;br&gt;
True&lt;br&gt;
False&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;4. Literal collections&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;These are;&lt;br&gt;
List&lt;br&gt;
Tuples&lt;br&gt;
Dictionaries&lt;br&gt;
Set&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;5.Special literals&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Python contains one special literal. "None", it is used to define a null variable. If "None" is compared with anything else than "None" it will return false.&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Keywords in python&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;These are reserved words that have a specific meaning and purposes and can't be used for anything else but those specific purposes. Note that keywords are different from python built in functions and types. Here are some of the python keywords;&lt;/p&gt;

&lt;p&gt;False   ,await, else,   import, pass,&lt;br&gt;
None,   break,  except, in, ,raise&lt;br&gt;
True,   class,  finally,    is, return,&lt;br&gt;
and,    continue,   for,    lambda, try,&lt;br&gt;
as, def,    from,   nonlocal,   while,&lt;br&gt;
assert, del,    global, not,    with,&lt;br&gt;
async,  elif,   if, or, yield&lt;/p&gt;

&lt;p&gt;You can read more about the key words &lt;br&gt;
&lt;a href="https://realpython.com/python-keywords/%5B%5D(url)"&gt;https://realpython.com/python-keywords/[](url)&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Operators in python.
&lt;/h1&gt;

&lt;p&gt;They are different types of python operators;&lt;br&gt;
&lt;strong&gt;1. Arithmetic operators&lt;/strong&gt;&lt;/p&gt;



&lt;p&gt;Used to perform mathematical operations like addiction, subtraction, multiplication and division.&lt;br&gt;
Operator    Description Syntax&lt;br&gt;
&lt;em&gt;+&lt;/em&gt; - x + y Addition: adds two operands &lt;/p&gt;



&lt;p&gt;&lt;em&gt;–&lt;/em&gt;   - x – y Subtraction: subtracts two operands &lt;/p&gt;



&lt;p&gt;&lt;em&gt;*&lt;/em&gt; - Multiplication: multiplies two operands   x * y&lt;/p&gt;



&lt;p&gt;&lt;em&gt;/&lt;/em&gt; - x / y Division (float): divides the first operand by the second   &lt;/p&gt;



&lt;p&gt;&lt;em&gt;//&lt;/em&gt;    - x // y Division (floor): The result will be rounded to the next smallest whole number.    &lt;/p&gt;



&lt;p&gt;&lt;em&gt;%&lt;/em&gt; - x % y Modulus: returns the remainder when the x is divided by y   &lt;/p&gt;



&lt;p&gt;&lt;em&gt;**&lt;/em&gt;    - x ** y Exponentiation: the result will be x raised to the power of y  &lt;/p&gt;




&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; x = 4
&amp;gt;&amp;gt;&amp;gt; y = 3
&amp;gt;&amp;gt;&amp;gt; x + y 
7
&amp;gt;&amp;gt;&amp;gt; x - y
1
&amp;gt;&amp;gt;&amp;gt; x * y
12
&amp;gt;&amp;gt;&amp;gt; x / y
1.3333333333333333
&amp;gt;&amp;gt;&amp;gt; x // y
1
&amp;gt;&amp;gt;&amp;gt;x % y 
1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;2. Membership operators&lt;/strong&gt;&lt;br&gt;
Used to test if a sequence with the specified value is present in the object.&lt;/p&gt;

&lt;p&gt;in - returns true if the specified sequence is present in the object&lt;/p&gt;

&lt;p&gt;not in - returns true if a sequence with the specified value is not present in the project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; x = ["pearls", "cherries"]
&amp;gt;&amp;gt;&amp;gt; print("pearls" in x)
True
# return True because the sequence "pearls" is present in the list

&amp;gt;&amp;gt;&amp;gt; print("banal" not in x)
True
# return True because the "banal" is not present in the list

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Comparison operators&lt;/strong&gt;&lt;br&gt;
Used to compare two values;&lt;br&gt;
&lt;em&gt;==&lt;/em&gt; equal&lt;br&gt;
&lt;em&gt;!=&lt;/em&gt; not equal&lt;br&gt;
&lt;em&gt;&amp;gt;&lt;/em&gt; greater than&lt;br&gt;
&lt;em&gt;&amp;lt;&lt;/em&gt; less than&lt;br&gt;
&lt;em&gt;&amp;gt;=&lt;/em&gt; greater than or equal to&lt;br&gt;
&lt;em&gt;&amp;lt;=&lt;/em&gt; less than or equal to&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Logical operators&lt;/strong&gt;&lt;br&gt;
used to combine conditional statement&lt;br&gt;
and - returns True both of the statements are true&lt;br&gt;
or - return True if one of the of the statement is true&lt;br&gt;
not - reverse the result, it returns False if the results is False&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; x = 4
&amp;gt;&amp;gt;&amp;gt; print(x &amp;gt; 3 and x &amp;lt; 10)
True 
# returns True 4 is greater than 3 and less than 10

&amp;gt;&amp;gt;&amp;gt; print(x &amp;gt; 3 or x &amp;lt; 3)
True 
# returns True because one of the statement is True

&amp;gt;&amp;gt;&amp;gt; print(not(x &amp;gt; 3 and x &amp;lt; 10))
False
# returns False as it reverses the result.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Identity operators&lt;/strong&gt;&lt;br&gt;
Used to compare objects, not if they are equal but if they are are actually of the same object, with the same memory location.&lt;br&gt;
is - return True if the both variables are of the same objects&lt;br&gt;
is not - returns True if both variables are not of the same objects&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; x = ["tea", "sugar"]
&amp;gt;&amp;gt;&amp;gt; y = ["tea", "sugar"]
&amp;gt;&amp;gt;&amp;gt; z = x
&amp;gt;&amp;gt;&amp;gt; print(x is z)
True
# returns True because z is the same object as x

&amp;gt;&amp;gt;&amp;gt; print(x is y)
False
# return False because x is not the same object as y, even if they have the same content. To understand this better you can use "==" operator which return True because x is #equal to y
&amp;gt;&amp;gt;&amp;gt; print (x == y)
True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Assignment operators&lt;/strong&gt;&lt;br&gt;
They are used to assign values to variables&lt;br&gt;
&lt;code&gt;=, !=, +=, -=, *=, /=,&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>An introduction to python data structures</title>
      <dc:creator>David-Gitonga</dc:creator>
      <pubDate>Wed, 13 Apr 2022 15:11:28 +0000</pubDate>
      <link>https://dev.to/davidgitonga/an-introduction-to-python-data-structures-l8l</link>
      <guid>https://dev.to/davidgitonga/an-introduction-to-python-data-structures-l8l</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.tourl"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jsMcKxU_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mjs219khozsihyazjiib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jsMcKxU_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mjs219khozsihyazjiib.png" alt="Image descrition" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.toPython%20machinelearning%20datascience"&gt;&lt;/a&gt;&lt;br&gt;
The purpose of this article is to give you an overview of data structures in python. A good grasp of data structures and algorithms and the ways to implement them will assist you solve challenges using code and create robust solutions to real world problems.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is a data structure?
&lt;/h2&gt;

&lt;p&gt;The specific way of organizing, managing and storing data in a computer is called a data structure. This efficient way of managing data allows us to perform various operations in the data such as adding, appending and removing as per the requirement of the programs.&lt;/p&gt;
&lt;h2&gt;
  
  
  Types of data structures
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i1N2fKNk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/23xxoih0pbbe64za7pm0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i1N2fKNk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/23xxoih0pbbe64za7pm0.png" alt="Image description" width="880" height="459"&gt;&lt;/a&gt;&lt;br&gt;
In this article we will be covering only the built in data structures.&lt;/p&gt;
&lt;h2&gt;
  
  
  List
&lt;/h2&gt;

&lt;p&gt;List is a type of data structure that contains a number of objects in a precise order to form a sequence to which elements can be added or removed. Each item is marked with a number corresponding to the order of the sequence, called index. In python index start at 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; list = [1,2,3,4]
&amp;gt;&amp;gt;&amp;gt; list
[1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  List comprehension
&lt;/h3&gt;

&lt;p&gt;This is basically creating a new list from a previous list.&lt;br&gt;
The syntax of list comprehension is &lt;code&gt;new_list = [ new_item for item in list&lt;/code&gt;] in which the new_item are values in your new_list.&lt;/p&gt;
&lt;h2&gt;
  
  
  Dictionaries
&lt;/h2&gt;

&lt;p&gt;Dictionaries are really useful as they help to group together and tag related pieces of information.&lt;br&gt;
Dictionaries are data structures in which a particular value is associated with a key value.&lt;br&gt;
The dictionary syntax is &lt;code&gt;dict={"name":"kelvin", "age":12,}&lt;/code&gt; in which the name and age are the keys while kelvin and 12 are the values. Note that items in a dictionary are separated using a comma.&lt;/p&gt;
&lt;h3&gt;
  
  
  Retrieving data from a dictionary.
&lt;/h3&gt;

&lt;p&gt;if you want to retrieve a piece af data from a dictionary, you just tap into the dictionary add a set of square bracket and inside provide the key name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt;dictionary ={"name": "kelvin", age: 23,}
&amp;gt;&amp;gt;&amp;gt;dictionary["name"]
&amp;gt;&amp;gt;&amp;gt;kelvin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When retrieving something from a dictionary make sure you get the spelling well.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure you use the correct data type.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Looping through a dictionary
&lt;/h3&gt;

&lt;p&gt;If you want to iterate the pairs of values in a dictionary you have to use the for-in construct. This is &lt;br&gt;
possible through the use of the items() function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; dict = {"name": kev, "age": 12}
&amp;gt;&amp;gt;&amp;gt; for (key, value) in dict.items():
    print(key)
&amp;gt;&amp;gt;&amp;gt; kev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Tuple
&lt;/h2&gt;

&lt;p&gt;It is a data type for immutable ordered sequences of elements. Immutable because you can’t add and remove elements from tuples, or sort them in place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sets
&lt;/h2&gt;

&lt;p&gt;Set is a mutable and unordered collection of unique elements. It can permit us to remove duplicate quickly from a list.&lt;/p&gt;

&lt;p&gt;Thankyou for reading this article. Hope you learnt something.&lt;br&gt;
Checkout my next article as we go through user defined data structures.&lt;/p&gt;

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