<?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: Joseph Ngahu</title>
    <description>The latest articles on DEV Community by Joseph Ngahu (@ngazz).</description>
    <link>https://dev.to/ngazz</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%2F814647%2Fc2b6211f-c190-478a-ad2c-8c849ffb365e.png</url>
      <title>DEV Community: Joseph Ngahu</title>
      <link>https://dev.to/ngazz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ngazz"/>
    <language>en</language>
    <item>
      <title>Python Memory management</title>
      <dc:creator>Joseph Ngahu</dc:creator>
      <pubDate>Sun, 24 Apr 2022 17:00:14 +0000</pubDate>
      <link>https://dev.to/ngazz/python-memory-management-4dob</link>
      <guid>https://dev.to/ngazz/python-memory-management-4dob</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Memory is simply a space for storing data in computers. We can also think of memory as book, if we need to write something we must open a page with some space enough for holding the characters we are going to write. This process of writing to a page with enough space to hold our writing can be equally be figured out as &lt;strong&gt;memory allocation&lt;/strong&gt; – providing space to hold a particular data in computer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Memory allocation
&lt;/h3&gt;

&lt;p&gt;We have two kinds of memory allocation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Static memory allocation&lt;/strong&gt;&lt;br&gt;
This technique is used in languages like C and C++, the static keyword is used during allocation of memory space. When we allocate static memory to data it means the memory cannot be reused ever in the program. Static memory is allocated during compilation of the program.&lt;br&gt;
&lt;code&gt;Static int a=10;&lt;/code&gt;&lt;br&gt;
In python, to achieve static memory allocation we implement a stack data structure. Here a function is defined with variables temporarily defined to it. Then the stack function returns the. The function call returns the value and the stack proceeds to the next task.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Dynamic memory allocation&lt;/strong&gt;&lt;br&gt;
Here the Heap is implemented; memory allocations happens during runtime of the program. In C and C++ &lt;code&gt;int a, char str[20]&lt;/code&gt; leads to automatic allocation and deallocation of memory spaces since we have a predefined size of the data but no length size information. For dynamic memory allocation the memory space can be used throughout the program.&lt;br&gt;
Heap memory allocation means the memory can be freed up if not in use or when the contents of the memory have been deleted.&lt;/p&gt;
&lt;h3&gt;
  
  
  Implementation of memory management in python
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Cpython&lt;/strong&gt;&lt;br&gt;
The default implementation of memory management in python is through CPython – a library which is written in C programing language. Python is interpreted and compiled down into bytecodes which are computer readable codes. For more information about Cpython refer to the following  &lt;a href="https://docs.python.org/3/c-api/index.html"&gt;documentation&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Garbage collector&lt;/strong&gt;&lt;br&gt;
The free memory is freed up in python. The GC module in python is used to carry out the object tracking. GC has three generations; first, second and third. A new object starts life at first generation when the python interpreter performs garbage collection and the object survives it moves to the second older generation and so on. For each generation, the garbage collector module has a threshold number of objects. If the number of objects exceeds that threshold, the garbage collector will trigger a collection process. For any objects that survive that process, they’re moved into an older generation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Import gc
gc.get_threshold()
#outputs (700,10,10)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;700 is the first generation, 10 the second generation and the other 10 refers to the third generation.&lt;br&gt;
Running a garbage collection process cleans up a huge amount of objects. &lt;br&gt;
The &lt;code&gt;gc.get_count()&lt;/code&gt; method is used to check number of generations in each count.&lt;br&gt;
More information about garbage collector can be found in the &lt;a href="https://stackify.com/python-garbage-collection/"&gt;following website&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  #Ways to reduce space complexity
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Avoid list slicing&lt;br&gt;
list slicing creates a copy of the object&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use list indexing carefully&lt;br&gt;
Instead of using &lt;code&gt;for index in range(len(array))&lt;/code&gt; use &lt;code&gt;for item in array&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid too much use of “+” operator in string concatenation &lt;br&gt;
instead try:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a=”millet”
a=a+” ugali”
print(a) #output millet ugali
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;instead of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a=”millet” +” ugali”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.javatpoint.com/python-memory-management"&gt;javapoint&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackify.com/python-garbage-collection/"&gt;stackify&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/c-api/index.html"&gt;Cpython&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/c-api/memory.html"&gt;Memory management&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Introduction to data structures and algorithms with Python</title>
      <dc:creator>Joseph Ngahu</dc:creator>
      <pubDate>Mon, 21 Feb 2022 18:06:18 +0000</pubDate>
      <link>https://dev.to/ngazz/introduction-to-data-structures-and-algorithms-with-python-4kek</link>
      <guid>https://dev.to/ngazz/introduction-to-data-structures-and-algorithms-with-python-4kek</guid>
      <description>&lt;p&gt;&lt;strong&gt;Data structure&lt;/strong&gt;&lt;br&gt;
is a named location which is used to store data in an organized way.&lt;br&gt;
&lt;strong&gt;Algorithm&lt;/strong&gt;&lt;br&gt;
are sequence of steps to be followed in order to perform a particular task&lt;/p&gt;

&lt;h3&gt;
  
  
  why data structure and algorithm
&lt;/h3&gt;

&lt;p&gt;Data structure and algorithm are essential for a number of tasks; this includes:&lt;br&gt;
&lt;strong&gt;Data search&lt;/strong&gt; incase where there is a massive or large volume of data and particular record is needed.&lt;br&gt;
To enhance &lt;strong&gt;multiple requests&lt;/strong&gt; in cases where many people want to access a resource.&lt;br&gt;
In enhancing &lt;strong&gt;processor speed&lt;/strong&gt; as data grows the processing speed also reduces too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Categories of Algorithms
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; Search − Algorithm to search an item in a data structure.&lt;/li&gt;
&lt;li&gt; Sort − Algorithm to sort items in a certain order.&lt;/li&gt;
&lt;li&gt;Insert − Algorithm to insert item in a data structure.&lt;/li&gt;
&lt;li&gt;Update − Algorithm to update an existing item in a data structure.&lt;/li&gt;
&lt;li&gt;Delete − Algorithm to delete an existing item from a data structure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Search
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def search(arr, n, x):

    for i in range(0, n):
        if (arr[i] == x):
            return i
    return -1

arr = [2, 3, 4, 10, 40]
x = 10
n = len(arr)
result = search(arr, n, x)
if(result == -1):
    print("Element is not present in array")
else:
    print("Element is present at index", result)

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sorting
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
def bubblesort(list):

# Swap the elements to arrange in order
   for iter_num in range(len(list)-1,0,-1):
      for idx in range(iter_num):
         if list[idx]&amp;gt;list[idx+1]:
            temp = list[idx]
            list[idx] = list[idx+1]
            list[idx+1] = temp
list = [19,2,31,45,6,11,121,27]
bubblesort(list)
print(list)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Insert
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def insertionSort(array):

    for step in range(1, len(array)):
        key = array[step]
        j = step - 1

        while j &amp;gt;= 0 and key &amp;lt; array[j]:
            array[j + 1] = array[j]
            j = j - 1

        # Place key at after the element just smaller than it.
        array[j + 1] = key


data = [9, 5, 1, 4, 3]
insertionSort(data)
print('Sorted Array in Ascending Order:')

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Update
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list1 = [1, 2, 3]
list2 = [5, 6, 7]
list3 = [10, 11, 12]

set1 = set(list2)
set2 = set(list1)

set1.update(set2)

print(set1)

set1.update(list3)
print(set1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Delete
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList = ["Bran",11,22,33,"Stark",22,33,11]

myList.remove(22)

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Data structure types
&lt;/h4&gt;

&lt;p&gt;Every programmer should be familiar with the following data structures:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Arrays&lt;/strong&gt;&lt;br&gt;
One of the simplest data structures, an array is a collection of items that are stored sequentially. An array contains values or variables—known as “elements”—of the same data type and is of a fixed size, so you cannot change the size of an array. Each item in an array is indexed starting with 0.&lt;/p&gt;

&lt;p&gt;The best way to think about an array is like a weekly medication organizer. It includes small containers lined up in a sequence, and each container has elements inside.&lt;/p&gt;

&lt;p&gt;Arrays are commonly used as structures for building other, more complicated data structures. They are also used for sorting algorithms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Linked Lists&lt;/strong&gt;&lt;br&gt;
A linked list is a sequence of items arranged in a linear order all connected to each other. This means you must access data in order, so random access to data is not possible.&lt;/p&gt;

&lt;p&gt;Each element in a linked list is called a “node,” and each node contains a key and a pointer. The pointer directs you to the next node, called a “next.” The sequence starts with a “head,” which directs you to the first element within the list. The last element of this list is known as the “tail.”&lt;/p&gt;

&lt;p&gt;You can create a singly linked list, which lets you traverse each item in a forward direction from the head to the tail. Similarly, you can create a doubly-linked list, which can be traversed both forward and backward. And finally, you can create a circular linked list in which the next pointer of the tail points to the head and vice versa, forming a circle.&lt;/p&gt;

&lt;p&gt;Linked lists are used for symbol table management in switching between programs using Alt + Tab (On a PC).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Stacks&lt;/strong&gt;&lt;br&gt;
A stack works almost exactly as it sounds. It’s like stacking elements within a tall container.&lt;/p&gt;

&lt;p&gt;Stacks are known as LIFO (Last In First Out) structures. This means the element placed last can be accessed first. You can “push” a new element onto the top of the stack, or you can “pop,” deleting the element inserted last which is at the top of the stack.&lt;/p&gt;

&lt;p&gt;Stacks are commonly used for parsing and evaluating mathematical expressions and to implement function calls in recursion programming.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Queues&lt;/strong&gt;&lt;br&gt;
A queue functions similarly to a stack, but instead of being a LIFO structure, it is a FIFO (First In First Out) structure. The easiest way to think about a queue is to think of a line of people waiting to enter a building. The person at the beginning of the line will enter the building first, while the person at the end will enter last.&lt;/p&gt;

&lt;p&gt;You can enqueue an element in this structure, which means inserting the element to the end of the queue. You can also dequeue an element, which means deleting an element from the beginning of the queue.&lt;/p&gt;

&lt;p&gt;Queues are often used to manage threads in multithreading, and they are (not surprisingly) used to implement priority queuing systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Hash Tables&lt;/strong&gt;&lt;br&gt;
A hash table structure associates each value with a key and then stores them. This makes it easy to look up values efficiently using a key. It’s an efficient way to insert and search for data regardless of its size, as it makes it easy to identify a specific object from a group of similar objects.&lt;/p&gt;

&lt;p&gt;For example, if you go to college, you may be assigned a unique student ID number. This ID number is a key that can be used to retrieve information about you and your student record.&lt;/p&gt;

&lt;p&gt;A hash table uses what’s known as a “hash function” to map a data set of any size to one of a fixed size—the hash table. The values that a hash function returns are known as “hash values.”  &lt;/p&gt;

&lt;p&gt;Hash tables are commonly used to create database indexes, to create associative arrays and to create a “set.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Trees&lt;/strong&gt;&lt;br&gt;
A tree is a structure similar to a linked list because each item is linked. But in a tree items are linked in a hierarchal fashion, just like you might see in a visual representation of someone’s family tree. There are various types of trees, each suited to different applications.&lt;/p&gt;

&lt;p&gt;For example, a binary search tree (BST) stores data in sorted order with every node in the binary comprised of the following attributes:&lt;/p&gt;

&lt;p&gt;Key (the value saved in the node)&lt;br&gt;
Left (pointer to the left child node)&lt;br&gt;
Right (pointer to the right child node)&lt;br&gt;
P (pointer to the parent node)&lt;br&gt;
Binary search trees are used in many different types of search applications. Other types of trees are used in wireless networking and to create expression solvers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Heaps&lt;/strong&gt;&lt;br&gt;
Similarly, a heap is a type of binary tree in which the parent nodes are compared to their children. This allows the values within the nodes to be arranged accordingly. Heaps can be represented as trees, but they can also be represented as binary arrays.&lt;/p&gt;

&lt;p&gt;There are two types of heaps. In a min heap, the parent’s key is less than or equal to the keys of its children. In a max heap, the parent’s key is greater than or equal to the keys of its children.&lt;/p&gt;

&lt;p&gt;Heaps are often used in algorithms to create priority queues, and to find the smallest or largest value in an array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Graphs&lt;/strong&gt;&lt;br&gt;
A graph is an abstract, non-linear data structure that is made of a finite set of nodes that are connected by edges. The nodes may be referred to as “vertices” and contain values, whereas the edges are simply lines or arcs that connect two nodes in the graph.&lt;/p&gt;

&lt;p&gt;Graphs are often used to represent networks, such as circuit networks or even paths in a city. They're great for solving real-world problems, but they can also be used as representations of digital networks.&lt;/p&gt;

&lt;p&gt;For example, on Facebook, each user could be represented with a node (or vertex). Each vertex could then contain information about that user, and each edge could represent their connection with another user.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Introduction to modern Python</title>
      <dc:creator>Joseph Ngahu</dc:creator>
      <pubDate>Mon, 14 Feb 2022 11:06:05 +0000</pubDate>
      <link>https://dev.to/ngazz/introduction-to-modern-python-3a6o</link>
      <guid>https://dev.to/ngazz/introduction-to-modern-python-3a6o</guid>
      <description>&lt;p&gt;Python datatypes&lt;br&gt;
Data type is a variable used to assign memory space in python. Though in python it is not necessarily to manually assign memory space for variables this happens automatically when a value is assigned to a variable.&lt;/p&gt;
&lt;h2&gt;
  
  
  String datatype
&lt;/h2&gt;

&lt;p&gt;String is a sequence of characters which are presented in quotation marks either single quotation marks or double quotation marks. Each time we make a change to the string variable a new string object is created.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
type(name) #outputs ‘str’&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##Set datatype##
Sets are unordered list of objects.
They are of two types:
-Sets
-Frozen sets
##Sets## 
Are immutable meaning new elements can be added or removed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
basket={“orange”,”banana”,”mango”}&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
print(basket) #outputs the element in basket variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##Frozen Sets##
They are immutable meaning no modification can be done to it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
cities=frozenset({“Nairobi”,”Nakuru”,”Kisumu”,”Mombasa”})&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
print(cities) #it outputs the elements in the  cities variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##Number datatype##
They are four types in python: int, long, float, complex.
-```

marks=10 #integer

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

&lt;/div&gt;

&lt;p&gt;-```&lt;br&gt;
&lt;br&gt;
longNumber=1234L #long&lt;br&gt;
&lt;/p&gt;

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

floatNumber=1.236 #float

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

&lt;/div&gt;

&lt;p&gt;-```&lt;br&gt;
&lt;br&gt;
ComplexNumber=12j #complex&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##List Datatype##
List datatype is similar to array whereby they elements are enclosed in square brackets []; list can store elements of different types unlike array which stores element of the same type.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 list1=[1,2,”abn”,1.3,”asdf”]”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##Tuple Datatype##
Tuples are similar to lists the difference is tuples cannot be changed and elements are enclosed in circular bracket ()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
tuple1=(“hello”)&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
tuple2=(1,2,3, “Word”)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##Dictionary datatype##
Dictionary consists of key-value pairs. It is enclosed by curly braces {} and values can be assigned and accessed using square brackets[].
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
dic={'name':'red','age':10}&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 print(dic) #will output all the key-value pairs. {'name':'red','age':10}&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 print(dic['name']) #will output only value with 'name' key. 'red'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##Indentation##
Indentation is used in python instead of semi-colons. Indentation is  can be achieved by using tab key or four spaces.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
class ExampleClass:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  Every function belonging to a class must be indented equally
&lt;/h1&gt;



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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
def &lt;strong&gt;init&lt;/strong&gt;(self):&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
name = "example"&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
def someFunction(self, a):&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 #Notice everything belonging to a function must be indented&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
if a &amp;gt; 5:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
return True&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

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

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
return False&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  If a function is not indented to the same level it will not be considers as part of the parent class
&lt;/h1&gt;



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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 def separateFunction(b):&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
for i in b:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  Loops are also indented and nested conditions start a new indentation
&lt;/h1&gt;



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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 if i == 1:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
return True&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

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

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
return False&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
separateFunction([2,3,5,6,1])&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Functions
Function is a module consisting of definition and statement
To declare a function we use ```

def

``` keyword
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
def say_hello():&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 print("Hello!")&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##Literals ##
A literal is a succinct and easily visible way to write a value. Literals represent the possible choices in primitive types for that language. Some of the choices of types of literals are often integers, floating point, Booleans and character strings. Python support the following literals:
-   String literals   ::   "halo" , '12345'
-   Int literals   ::   0,1,2,-1,-2
-   Long literals   ::   89675L
-   Float literals   ::   3.14
-   Complex literals   ::   12j
-   Boolean literals   ::   True or False
-   Special literals   ::   None
-   Unicode literals   ::   u"hello"
-   List literals   ::   [], [5,6,7]
-   Tuple literals   ::   (), (9,),(8,9,0)
-   Dict literals   ::   {}, {'x':1}
-   Set literals   ::   {8,9,10}
##Type conversion##
Is the process of converting a value of a particular data type to another datatype.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
marks= 100&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
print(type(marks)) #returns int&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
print(str(marks)) #returns ‘100’




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

&lt;/div&gt;

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