<?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>Forem: Gowtham Venkatesan</title>
    <description>The latest articles on Forem by Gowtham Venkatesan (@gothamv).</description>
    <link>https://forem.com/gothamv</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%2F194803%2F8ed39a44-6e4a-450d-9ad2-3b3d94bdc039.png</url>
      <title>Forem: Gowtham Venkatesan</title>
      <link>https://forem.com/gothamv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gothamv"/>
    <language>en</language>
    <item>
      <title>Python Lists in under 10 minutes</title>
      <dc:creator>Gowtham Venkatesan</dc:creator>
      <pubDate>Sat, 08 Aug 2020 11:41:36 +0000</pubDate>
      <link>https://forem.com/gothamv/python-lists-in-under-10-minutes-3nj3</link>
      <guid>https://forem.com/gothamv/python-lists-in-under-10-minutes-3nj3</guid>
      <description>&lt;p&gt;In the previous &lt;a href="https://dev.to/gothamv/python-strings-in-under-10-minutes-1e70"&gt;post&lt;/a&gt;, we discussed about the String data type. In this post let’s discuss the List data type. List is an ordered collection data type. It’s like an array. Think of it as a variable but instead of a single value you can store multiple values in it. And the values inside these lists can be a combination of numbers, strings, or lists(list inside a list) etc. Lists are indexable and they support slicing as well. Let’s learn all about them!&lt;/p&gt;

&lt;h3&gt;
  
  
  Declaring a variable of the List Type:
&lt;/h3&gt;

&lt;p&gt;The syntax for list : variableName = []. And inside these square brackets, we add the values we want separated by commas. The following example will make things clear.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList = [1, 2, 3, 4, 5] #This is list
print(type(myList))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We can store any type of value inside a list. For example, we can store a list of strings. Or we can create a list with both numbers and strings. Or we can even have a list inside a list.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    myList2 = ["Hello", "This", "Is", "A", "List"]
    myList3 = ["A", "List", "can also contain numbers", 1, 2, 2.2]
    print(type(myList2))
    print(type(myList3))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Run the code below and check it out:&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/lists?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;h3&gt;
  
  
  You can combine two lists by using the + sign:
&lt;/h3&gt;

&lt;p&gt;Paste the code below in the repl window above and run it.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList = [1, 2, 3]
myList2 = [4, 5]
myList3 = myList + myList2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;So now myList3 will contain [1, 2, 3, 4, 5] . Same goes for lists consisting of a combination of multiple data types. It just adds the list to the right of the + operator to the list on the left of the + operator.&lt;/p&gt;
&lt;h3&gt;
  
  
  Accessing elements in the list:
&lt;/h3&gt;

&lt;p&gt;Because Lists are an ordered sequence of data items we can index them. Just like in Strings. You can access elements inside the list using a method called &lt;strong&gt;Indexing&lt;/strong&gt;. Meaning &lt;strong&gt;every data item in the list has a number associated with it&lt;/strong&gt;. Using these numbers we can grab parts of the list and we can manipulate them without affecting the original List. All you have to do is pass in the position of the element you want to access to the list. It is important to note that the position of elements in a list or any data type that is indexable starts with 0. Let’s look at an example.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList = [1, 3, "Four", 5, "Six", 7]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  A List can be indexed in two ways:
&lt;/h3&gt;

&lt;p&gt;1: Positive Indexing&lt;/p&gt;

&lt;p&gt;2: Negative or reverse indexing&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ji27M1re--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/7264/1%2Af-Dsp2GrZmMZqwpYl9StBw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ji27M1re--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/7264/1%2Af-Dsp2GrZmMZqwpYl9StBw.jpeg" alt="myList indexing"&gt;&lt;/a&gt;&lt;em&gt;myList indexing&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  1: Positive Indexing:
&lt;/h3&gt;

&lt;p&gt;In positive indexing, the list is numbered from &lt;strong&gt;left to right starting with 0&lt;/strong&gt;. Yes 0. You start numbering from 0. So &lt;strong&gt;0 will the index value of the first data item&lt;/strong&gt; in the list, 1 will be the index value of the second item in the list and so on …&lt;/p&gt;
&lt;h3&gt;
  
  
  2: Negative Indexing:
&lt;/h3&gt;

&lt;p&gt;In negative indexing, the list is numbered from the &lt;strong&gt;right to left start with negative 1&lt;/strong&gt;. So -1 will the be the index of the first item from the right and you increment as you go on …&lt;/p&gt;
&lt;h3&gt;
  
  
  So to grab a data item from the list:
&lt;/h3&gt;

&lt;p&gt;Syntax : listName[index]&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = myList[0]  # stores 1 in a 
b = myList[5]  # stores 7 in b
c = myList[-1] # stores 7 in c
d = myList[-2] # stores 'Six' in d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/list2?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;Now, what if we wanted to access multiple items in the list at once?&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessing elements in the list using Slicing:
&lt;/h3&gt;

&lt;p&gt;Using slicing we can use &lt;strong&gt;indexing&lt;/strong&gt;to grab multiple items of the list. Here’s the Syntax : listName[startIndex : stopIndex].&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;stop index is excluding&lt;/strong&gt; meaning it’ll grab the items only until the stop index but not including the character at the stop index. The &lt;strong&gt;start index is inclusive of the item at the start index&lt;/strong&gt;. Run the code below.&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/list3?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;If you don’t understand the code above learn more about slicing in detail check out my &lt;a href="(https://dev.to/gothamv/python-strings-in-under-10-minutes-1e70)"&gt;previous post&lt;/a&gt; on Strings where I explain the very same in-depth. Negative Slicing alone doesn’t work as expected with slicing in lists. Negative indexing is possible and will work just fine. Just not negative slicing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding elements to the list:
&lt;/h3&gt;

&lt;p&gt;Now if we want to add elements to the list we can use the methods append(), insert() and extend().&lt;/p&gt;

&lt;p&gt;1: &lt;strong&gt;append():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using append we can add a single element at the end of the list. &lt;br&gt;
In the append() method you simply pass the element to it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We’ll learn more about what passing means when we learn about functions in python. For now, think of it as sending something to this line of code which in-turn makes use of some other lines of code which python knows by default.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If it is just numbers you don’t have to bother about the ‘’ . If it is a character or a string you must enclose it in a ‘’ or “”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    myList = [1]
    myList.append(2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;2: &lt;strong&gt;insert():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using the insert() method we can add elements at a specific index in the list.&lt;br&gt;
In the insert() method we pass in the index (position) we want to add the element followed by the actual element. This will add the element at the specified index pushing the other elements in the list towards the right.&lt;br&gt;
`&lt;br&gt;
    myList1 = [1, 3, 4, 5]&lt;br&gt;
    myList1.insert(1, 2)&lt;/p&gt;

&lt;p&gt;3: &lt;strong&gt;extend():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the extend() method we need to pass the elements to it as another list (in [] separated by commas).&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList2 = ["Hello"]
myList2.extend(["World", "!"])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;If you just pass in using ‘’ or “” it’ll add each character of the element as a new item on the list you are performing the method on.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList3 = ['H', 'E', 'L']
myList3.extend('LO')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Run the code below to see the output of the above code.&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/lists2?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;h3&gt;
  
  
  Deleting elements from the list:
&lt;/h3&gt;

&lt;p&gt;Now if we want to delete elements from the list we can use the pop(), del() or the remove() methods.&lt;/p&gt;

&lt;p&gt;1: &lt;strong&gt;pop():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The pop() method will remove a single element from the end of the list each time it is used. You can optionally pass the index to the pop() method to delete elements at a particular index.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList = [1, 2, 2, 3, 4, 5, 5]
myList.pop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;2: &lt;strong&gt;del():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using the del() method we can delete an element at a specific index. You need to pass the index of the element you want to delete to it. The del() syntax is a little different. We use del Listname[index]. The only difference between del() and pop() is that pop() returns the element that is being deleted while the del() does not.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;del myList[5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;3: &lt;strong&gt;remove():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And using the remove() we can remove the first occurrence of the element in the list. Meaning if the list1 has [1,2,3,2,4] using remove(2) on it deletes the 2 at index 1 and not the one index 3 as well. It stops after deleting the first occurrence the element you pass to it.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList.remove(2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/lists3?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;h3&gt;
  
  
  Bonus operations on List:
&lt;/h3&gt;

&lt;p&gt;There are a few additional useful methods that you can apply to Lists such as sort(), reverse(), extend() and index().&lt;/p&gt;

&lt;p&gt;1: &lt;strong&gt;sort():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your list consists of numbers you can use the sort method to store the numbers in the list in ascending or descending order. Same goes for strings in the list(based on the first character of the string). This ascending/descending order is dependent on the actual values of the elements in the list. For descending order alone we need to pass something a little special to the method. We need to pass reverse &lt;strong&gt;=&lt;/strong&gt; True to the sort() method for descending.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList = [1, 4, 8, 9, 3]
myList.sort() 
myList.sort(reverse = True)
myList1 = ['a', 'z', 'y', 'e', 'b']
myList1.sort()
myList1.sort(reverse = True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;2: &lt;strong&gt;reverse():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As the name suggests, it is used to reverse the elements in the list but based on the index and not on the actual values.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList2 = [1, 3, 2, 5, 6]
myList2.reverse()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;3: &lt;strong&gt;extend():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using the extend() method we can combine two lists just like we did with + operator we discussed earlier.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList = [1, 2, 3]
myList2 = [4, 5]
myList.extend(myList2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This method updates the list we were applying it to show the concatenation of the two original lists.&lt;/p&gt;

&lt;p&gt;4: &lt;strong&gt;index():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This method searches for the element we pass to it from the start of the list and returns its index. If the given element isn’t present it throws an error.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myList = [1, 2, 3]
index = myList.index(3)
print(index)
# index2 = myList.index(4)
# The above line will throw an error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/lists4?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;In this post we learned about the List Data Type, how to declare it, add lists together, indexing, slicing and it’s madness. We learnt some useful methods that we can apply on Lists as well. We can also have lists inside a list, even dictionaries, sets and tuples. We’ll learn more about them in a later post.&lt;/p&gt;

&lt;h3&gt;
  
  
  And that’s pretty much it for the List Data Type in Python. What? I’m serious. This is all you need to know about Lists. For Now.
&lt;/h3&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;p&gt;Next up: It's all about sets.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Python Strings in under 10 minutes</title>
      <dc:creator>Gowtham Venkatesan</dc:creator>
      <pubDate>Sat, 08 Aug 2020 11:22:27 +0000</pubDate>
      <link>https://forem.com/gothamv/python-strings-in-under-10-minutes-1e70</link>
      <guid>https://forem.com/gothamv/python-strings-in-under-10-minutes-1e70</guid>
      <description>&lt;p&gt;In the &lt;a href="https://dev.to/gothamv/python-numbers-in-under-10-minutes-55da"&gt;previous post&lt;/a&gt;, we discussed the numbers data type. In this post, we'll discuss about the String data type.&lt;/p&gt;

&lt;p&gt;Every value that we work with in Python has a type. A &lt;strong&gt;data type&lt;/strong&gt; is a classification that specifies which type of value a variable has and what type of operations can be applied to it. This post is a quick introduction to the &lt;strong&gt;String&lt;/strong&gt; data type in python. Let’s get started!&lt;/p&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;h2&gt;
  
  
  Strings
&lt;/h2&gt;

&lt;p&gt;An ordered sequence of characters is called a &lt;strong&gt;String&lt;/strong&gt;. Anything under a ‘ ‘ single-quote or a “ “ is a string. It is used to store sentences, words, characters, special symbols, spaces etc. A username is an example of where strings might be used in real life.&lt;/p&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;h2&gt;
  
  
  Declaring the String Data Type:
&lt;/h2&gt;

&lt;p&gt;All you have to do is assign a variable name to the string of your choice in ‘’ or a “”. And that’s pretty much it.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myStr = 'a'
myStr2 = "The quick brown fox jumps over the lazy dog"
myStr3 = "!@#$%^&amp;amp;*()_+"
myStr4 = '222'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Run the code below and see for yourself :&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/strings?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;Any sequence of characters. ANY. Anything under a ‘ ‘ or a “ “ is a string.&lt;br&gt;
Even if it’s a number and it’s inside a ‘ ‘ it’s considered as a string. I repeat ANY. ANYTHING INSIDE IT.&lt;/p&gt;
&lt;h3&gt;
  
  
  You can also add strings using the + operator:
&lt;/h3&gt;

&lt;p&gt;The code below is pretty self-explanatory. Run the code and see the results.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myStr = "Hello"
myStr2 = "World"
myStr3 = myStr + myStr2 + "!"
print(myStr + myStr2 + "!")
print("Hello" + myStr2 + "!")
print(myStr + "World" + "!")
print("Hello" + "World" + "!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/string?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;h2&gt;
  
  
  Indexing :
&lt;/h2&gt;

&lt;p&gt;Because strings are an ordered sequence of characters we can index them. Meaning &lt;strong&gt;every character in the string has a number associated with it&lt;/strong&gt;. Using these numbers we can grab parts of the string and we can manipulate them without affecting the original string. Let me show you what I’m talking about.&lt;/p&gt;

&lt;p&gt;Let’s Look at an example of the string “Lasagna”. Let’s declare it.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString = "Lasagna" #This is a string
myString = 'Lasagna' # You can also use ' ' instead of " "
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;A String can be indexed in two ways:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Positive Indexing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Negative or reverse indexing&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C4lu8cYv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4124/1%2A9voko6oLixeUbvKWq1OIAA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C4lu8cYv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4124/1%2A9voko6oLixeUbvKWq1OIAA.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;1. Positive Indexing:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In positive indexing, the string is numbered from &lt;strong&gt;left to right starting with 0&lt;/strong&gt;. Yes 0. You start numbering from 0. So &lt;strong&gt;0 will the index value of the first character&lt;/strong&gt; in the string, 1 will be the index value of the second character and so on …&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;2. Negative Indexing:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In negative indexing, the string is numbered from the &lt;strong&gt;right to left start with negative 1&lt;/strong&gt;. &lt;em&gt;For Obvious reasons. You do know right?&lt;/em&gt;. So -1 will the be the index of the first character from the right and you increment as you go on …&lt;/p&gt;
&lt;h3&gt;
  
  
  So to grab a character from a string:
&lt;/h3&gt;

&lt;p&gt;Syntax : variableName[index]&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString = "Lasagna"
a = myString[0]  # stores 'L' in a 
b = myString[6]  # stores 'a' in b
c = myString[-1] # stores 'a' in c
d = myString[-5] # stores 's' in d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Edit the code below and try to grab ‘g’ and store it in a new variable e.&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/strings1?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Any character in a string is indexable.&lt;/strong&gt; Even &lt;strong&gt;spaces&lt;/strong&gt; in between sentences. So even the spaces should be numbered and considered during indexing.&lt;/p&gt;

&lt;p&gt;Okay so now what if we want to grab multiple characters? This is where &lt;strong&gt;slicing&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;h2&gt;
  
  
  Slicing:
&lt;/h2&gt;

&lt;p&gt;In slicing we’ll use &lt;strong&gt;indexing&lt;/strong&gt; to grab a portions of the original string. Here’s the Syntax : variableName[startIndex : stopIndex].&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString = "The Council of Water Sheep"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ND5C452G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/7264/1%2AFr6JUGl0DiwjyHmJ9XBanw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ND5C452G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/7264/1%2AFr6JUGl0DiwjyHmJ9XBanw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Say for example you want to grab the first 10 characters in the myString variable. All you have to do is mention the start index followed by a : then the stop index. The &lt;strong&gt;stop index is excluding&lt;/strong&gt; meaning it’ll grab the characters only until the stop index but not including the character at the stop index. The &lt;strong&gt;start index is inclusive&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So we can modify the syntax as follows: variableName[startIndex : stopIndex + 1]. The + 1 is to include the character at the stop index. Just increment it to the next number. In the case of negative indexing if the index is -16 for example, incrementing it by one should give you -15 and so on...&lt;br&gt;
This slicing operation isn’t visible in the output section unless you print it or store it in a variable and then print it.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;So let’s try and grab the first 10 characters:&lt;/strong&gt; “The Council” :
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BsF8sAoh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4124/1%2Ao0KZex8P-srQHsixjOCuvQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BsF8sAoh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4124/1%2Ao0KZex8P-srQHsixjOCuvQ.jpeg" alt="First 10 characters of myString"&gt;&lt;/a&gt;&lt;em&gt;First 10 characters of myString&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Positive Indexing :
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = myString[0:11]
print(a) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;0 is the start of the index and 10 is the stop index for the substring we are trying to grab. But since the stop index isn’t inclusive we increment it to 11.&lt;/p&gt;
&lt;h3&gt;
  
  
  Negative Indexing :
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString[-26:-15]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;-26 is the start index and -16 is the stop index. But we increment it to -15. &lt;em&gt;Why?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We normally use negative indexing to access the characters towards the end of the string as it is easier to number. But you can use negative indexing to grab the characters at the beginning of the string as well.&lt;/p&gt;

&lt;p&gt;Refer to the index mapping of the string in the image above to get a better understanding.&lt;/p&gt;
&lt;h3&gt;
  
  
  Now let’s grab ‘water’ from the string :
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MXFBoj6X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4124/1%2AjjL6Pljn81xSamE4jnpgLQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MXFBoj6X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4124/1%2AjjL6Pljn81xSamE4jnpgLQ.jpeg" alt="WATER substring from myString"&gt;&lt;/a&gt;&lt;em&gt;WATER substring from myString&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Positive Indexing :
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString[15:20]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Negative Indexing :
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString[-11:-6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Run the code below to check it out!&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/strings3?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Let’s grab the last 8 characters now :&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VUlx4Glt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4124/1%2ALtwBiS8pDMeTafVj2QjfVw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VUlx4Glt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4124/1%2ALtwBiS8pDMeTafVj2QjfVw.jpeg" alt="The last 8 characters of myString"&gt;&lt;/a&gt;&lt;em&gt;The last 8 characters of myString&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Positive Indexing
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString[18:26]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Should work just fine. As expected.&lt;/p&gt;
&lt;h3&gt;
  
  
  Negative Indexing
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString[-8:-1] # Something's wrong I can feel it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Something’s wrong in the above line of code. The last character has the value of -1. You can’t increment it to 0 and expect it to return the desired outcome. It messes up the order. So you leave the stop index blank. Don’t freak out. Just keep reading.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Leaving the start or stop index blank:&lt;/strong&gt;
&lt;/h3&gt;
&lt;h3&gt;
  
  
  Case 1 : Stop index is blank:
&lt;/h3&gt;

&lt;p&gt;If we leave the stop index blank then the slicing will grab &lt;strong&gt;all the characters from the start index till the end of the string&lt;/strong&gt;. Let’s try and grab the ‘Sheep’ substring from myString.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString[21:] # Positive indexing
myString[-8:] # Negative indexing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;21 / -8 is the start of the index for the substring ‘Sheep’. We specify the start string alone and leave the stop index blank so it’ll grab everything from 21 / -8 till the very end of the string.&lt;/p&gt;
&lt;h3&gt;
  
  
  Case 2 : Start index is blank:
&lt;/h3&gt;

&lt;p&gt;If we leave the start index blank then the slicing will grab &lt;strong&gt;all the characters from the start of the string till the stop index&lt;/strong&gt;. Let’s grab the first 10 characters of myString by leaving the start index blank.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString[:10] # Positive indexing
myString[:-16] # Negative indexing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;10 / -16 is the stop index to grab the first 10 characters from the string. We leave the start index blank. So this slicing operation grabs everything from the start of string until the stop index.&lt;/p&gt;
&lt;h3&gt;
  
  
  Case 3 : Both Start and Stop index are blank:
&lt;/h3&gt;

&lt;p&gt;If both the start and stop index is blank then the slicing operation will grab the entire string. Because there is no start or stop conditions mentions.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString[:]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/strings4?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;h3&gt;
  
  
  There’s this thing called the step index:
&lt;/h3&gt;

&lt;p&gt;Optionally you can include this thing called the &lt;strong&gt;step value&lt;/strong&gt; using which you can skip characters which are grabbed during the slicing operation. This step index is right after the stop index.&lt;br&gt;
Syntax : variableName[startIndex : stopIndex: stepValue]&lt;/p&gt;

&lt;p&gt;So if we set the stop value as 2 it’s going to skip 2 characters for every 2 characters grabbed.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString = "Encyclopaedia"
myString[0:8:2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;So the above code is going to grab the characters from the start index until the stop index 8 but only every 2 alternate characters.&lt;/p&gt;

&lt;p&gt;So normally if the slicing was myString[0:8] it would grab the substring : Encyclop. But if we add the step value myString[0:8:2] it would return Ecco.&lt;/p&gt;

&lt;p&gt;You can leave the start/stop/step values blank in any varying combinations. Let me show you what I’m talking about.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myString[0::3]
myString[:6:2]
myString[::2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Run the code to see the results :&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/strings5?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;Well, I hope you understood slicing properly. We’ll be using this concept in other data types as well. So get comfortable with it. It isn’t going anywhere.&lt;/p&gt;

&lt;p&gt;If you’ve reached till here, GOOD JOB! Baby steps! One at a time! In this post, we learned about the Strings Data Type, how to declare it, add strings together, indexing, and slicing. We have some useful methods that we can apply on strings. We’ll look at them in another post. We need to learn a few more concepts first.&lt;/p&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;h3&gt;
  
  
  And that’s pretty much it for the Strings Data Type in Python. What? I’m serious. This is all you need to know about String. For Now.
&lt;/h3&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;p&gt;Next up: &lt;a href="https://dev.to/gothamv/python-lists-in-under-10-minutes-3nj3"&gt;It's all about lists&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Python Numbers in under 10 minutes</title>
      <dc:creator>Gowtham Venkatesan</dc:creator>
      <pubDate>Sat, 08 Aug 2020 11:01:58 +0000</pubDate>
      <link>https://forem.com/gothamv/python-numbers-in-under-10-minutes-55da</link>
      <guid>https://forem.com/gothamv/python-numbers-in-under-10-minutes-55da</guid>
      <description>&lt;p&gt;// If you're new to Python, I suggest you read my previous &lt;a href="https://dev.to/gothamv/get-started-with-python-in-under-10-minutes-3a5j"&gt;post&lt;/a&gt; where you can get started with Python in under 10 minutes.&lt;/p&gt;

&lt;p&gt;Every value that we work with in Python has a type. A &lt;strong&gt;data type&lt;/strong&gt; is a classification that specifies which type of value a variable has and what type of operations can be applied to it. It’s as simple as that. This article is a quick introduction to the &lt;strong&gt;Numbers&lt;/strong&gt; data type in python. So let’s get started!&lt;/p&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;h2&gt;
  
  
  Numbers
&lt;/h2&gt;

&lt;p&gt;Numbers are the most basic data types in Python. Any number that you assign to a variable is of the data type &lt;strong&gt;Number&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now within Numbers, there are three classes :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integer&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Floating point numbers&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complex Numbers&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are the types of Numbers Python supports.&lt;/p&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Integer (int) :
&lt;/h2&gt;

&lt;p&gt;Any and every whole number falls in ‘int’ class. Any number without decimals is an Integer.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar1 = 20
myVar2 = 10000
myVar3 = 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Let’s quickly check the type of the above variables using the type() method.&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/integer?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;Run the code by hitting the big green play button. You can also edit the code and run it as well.&lt;/p&gt;

&lt;p&gt;If you run the code above by clicking on the big green play button, you’ll get an output saying these variables are of . This tells us the type(class) the variable belongs to.&lt;/p&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Floating Point Numbers (float) :
&lt;/h2&gt;

&lt;p&gt;All decimal numbers fall under the ‘float’ class. Any number with decimals is of a float type. The result of a division operation between two numbers results in a floating-point number. Even if the result is a whole number it will be converted to floating-point.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar = 1.2345
myVar2 = 1231.232323
myVar3 = 6/3  
# Even though the result is 3 which is a whole number, it will be be converted to a floating point number resulting in the value 3.00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Let’s quickly run the above code:&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/float?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;If you run the code above, you’ll get an output saying these variables are of the .&lt;/p&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Complex Numbers (complex) :
&lt;/h2&gt;

&lt;p&gt;Complex numbers are specified as  + j. Just like how you would do in regular math. But this type is rarely used.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar = 2 + 3j
myVar2 = 6 + 3j
print(type(myVar))
print(type(myVar2))
print(myVar + myVar2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Run the code below!&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/numbers3?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;If you check the type of the above variable, it’ll return .&lt;/p&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;h2&gt;
  
  
  Operations on Numbers:
&lt;/h2&gt;

&lt;p&gt;We can perform the basic mathematical operations on numbers using what is known as an “operator”. It’s nothing but a symbol that defines what type of operation you want to perform on numbers. You can use these operators to perform operations on variables containing numbers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z67RJbcV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4124/1%2A8r78oufqmo5_C1uv_BQq9g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z67RJbcV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4124/1%2A8r78oufqmo5_C1uv_BQq9g.jpeg" alt="Gotta love gradients"&gt;&lt;/a&gt;&lt;em&gt;Gotta love gradients&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Addition :
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;+&lt;/strong&gt; operator is used for addition.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar1 = 1 + 2
myVar2 = 3 + 5
myVar3 = myVar1 + myVar 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Subtraction :
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;-&lt;/strong&gt; operator is used for subtraction.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar1 = 1 - 2
myVar2 = 3 - 5
myVar3 = myVar1 - myVar 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Multiplication :
&lt;/h3&gt;

&lt;p&gt;The *****operator is used for multiplication.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar1 = 1 * 2
myVar2 = 3 * 5
myVar3 = myVar1 * myVar 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Division :
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;/&lt;/strong&gt; operator is used for division.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar1 = 4 / 2
myVar2 = 2 / 1
myVar3 = myVar1 * myVar 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Modulus :
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;%&lt;/strong&gt; operator is used to find the remainder of a division operation.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar = 6 % 4
# Which will give you 2.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Exponent or Power or whatever:
&lt;/h3&gt;

&lt;p&gt;The ** operator is used to raise the number on the left side of the operator to the power of the number on the right side of the operator.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar = 2 ** 3
myVar2 = 2 ** 2
myVar3 = 3 ** 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Okay so now let’s run the code on a repl portal and see the results.&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/numbers4?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;You can also use () to separate multiple mathematical operations just like you would on a calculator.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar = (1 + 2) * (3 / 4)
myVar = (3 * 4) / (6 / 3)
myVar = ((3 * 4) / (6 / 3) - (1 + 2) * (3 / 4))
# And so on ...
# You get the point. Right?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you’ve reached till here, GOOD JOB! You’ve taken your first steps into learning Python. In this post we learned about the Numbers Data Type, it’s subtypes and the operations you can perform on it. In the next post, we’ll learn more about strings.&lt;/p&gt;

&lt;h3&gt;
  
  
  And that’s pretty much it for the Numbers Data Type in Python. What? I’m serious. This is all you need to know about numbers in Python.
&lt;/h3&gt;

&lt;p&gt;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬&lt;/p&gt;

&lt;p&gt;Next up: &lt;a href="https://dev.to/gothamv/python-strings-in-under-10-minutes-1e70"&gt;Strings in Python&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Get Started with Python in under 10 minutes</title>
      <dc:creator>Gowtham Venkatesan</dc:creator>
      <pubDate>Sun, 11 Aug 2019 06:30:28 +0000</pubDate>
      <link>https://forem.com/gothamv/get-started-with-python-in-under-10-minutes-3a5j</link>
      <guid>https://forem.com/gothamv/get-started-with-python-in-under-10-minutes-3a5j</guid>
      <description>&lt;p&gt;So you want to learn how to code? You have no prior coding experience or are you coming from another programming language? You have come to the right place. This is an ultimate beginners guide to Programming with Python. We’re not going to go knees deep into programming. But we’re going to get started and write code as quickly as possible. So let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Part I: Setting up the coding environment
&lt;/h2&gt;

&lt;p&gt;You can write Python code on your terminal, VSCode or even on a dedicated IDE like PyCharm. But since you’re a beginner we don’t want to you waste time setting one up. You can do it later. For now, you can look to the cloud for an easy and instant IDE setup.&lt;/p&gt;

&lt;p&gt;Go to &lt;a href="https://repl.it" rel="noopener noreferrer"&gt;Repl.it&lt;/a&gt;. It gives you an instant IDE to learn, build, collaborate, and host all in one place.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a new Repl.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose Python (not Python 2.7).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Name your Repl.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create Repl.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AQXQFArTYxQlZfFzI9YyysQ.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AQXQFArTYxQlZfFzI9YyysQ.gif" alt="Follow the GIF if you have any confusions."&gt;&lt;/a&gt;&lt;em&gt;Follow the GIF if you have any confusions.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now that we have an IDE, let’s write our first line of code!&lt;/p&gt;

&lt;h2&gt;
  
  
  Part II: Let’s Write Some Code!
&lt;/h2&gt;

&lt;p&gt;Before you start coding, in any programming language it’s a tradition to get started by writing code to print “Hello World!” So let’s not break tradition and do just that!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Let’s print stuff using Python :
&lt;/h2&gt;

&lt;p&gt;The middle section of the repl is where you write your code. The right side is called a console. Think of it as the middle man between you and python. The console is where you’ll do your input/output to your python program.&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F6816%2F1%2ACNoFX5BkVE5aLSN_vPMnKg.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%2Fcdn-images-1.medium.com%2Fmax%2F6816%2F1%2ACNoFX5BkVE5aLSN_vPMnKg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To print something on the console, we use the print() statement. Specify the text you want to print inside ‘ ’ or “ ” quotes.&lt;/p&gt;

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

&lt;/div&gt;
&lt;p&gt;After writing the above code in the console hit the Run button on top.&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AmH4OsX34RB1-mmU18PbEBQ.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AmH4OsX34RB1-mmU18PbEBQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! You have written your first piece of Python Code! Now let’s go ahead write some code that actually does something.&lt;/p&gt;

&lt;p&gt;By now you should be familiar with how to use repl.it. From now I’ll embed the repl directly here in the article so you don’t have to keep switching tabs which can quickly become really annoying. So you can write in your own code and run them right here!&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Comments in Python
&lt;/h2&gt;

&lt;p&gt;Comments are used to explain what your line of code does. You can write a comment using the ‘#’ symbol. The ‘#’ tells python to ignore the line and not to execute it. You can even add # symbol before existing lines of code to make it a comment. You can also have multi-line comments by starting and ending it with ‘’’. Refer the example below for clarity.&lt;/p&gt;

&lt;p&gt;Tap the big green play button below to execute the code. You can also edit the code here. Add in your lines of code and run them!&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/comments?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Variables in Python
&lt;/h2&gt;

&lt;p&gt;Think of variables like a box, where you store stuff. You can store numbers, characters, sentences and so much more. For now let’s work with numbers, characters, and sentences(strings).&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s assign a number to a variable.
&lt;/h3&gt;

&lt;p&gt;Equal to symbol ‘=’ is an assignment operator and is used to assign values to variables.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVariable = 13
myVariable2 = 12.6969
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;You can go ahead and check the type of your variable using the type() statement, and passing in your variable name inside of the type().&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type(myVariable)
type(myVariable2)

# To view this in the console pass the above statement inside the print function like this :

print(type(myVariable))
print(type(myVariable2))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;When you run the above code you’ll see that myVariable returned  and myVariable2 returned .&lt;/p&gt;

&lt;p&gt;You might’ve guessed it. It’s because 13 is an integer and 12.6969 is a decimal number which we call it as floating-point numbers in the programming world.&lt;/p&gt;
&lt;h3&gt;
  
  
  Let’s assign a character/string to a variable.
&lt;/h3&gt;

&lt;p&gt;To assign a character to a variable, you must enclose the value of the variable in ‘ ’(single quotes) or “ “(double quotes).&lt;/p&gt;

&lt;p&gt;Characters by convention have a length of one and use ‘ ‘ (single quotes).&lt;br&gt;
Strings are sentences or have more than one character generally enclosed in &lt;br&gt;
“ “ (double quotes).&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;char1 = 'a'
string1 = "Musk Cult"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Run the code below and see for yourself!&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/variablesInPython?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Arithmetic Operations in Python
&lt;/h2&gt;

&lt;p&gt;Remember we created number valued variables above? You can perform mathematical operations on them. Let’s see the implementation of some of the basic arithmetic operations in math.&lt;/p&gt;

&lt;p&gt;The code below is pretty self-explanatory. Run the code and check it out.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVariable1 = 6
myVariable2 = 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Addition + :
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVariable + myVariable2

# To see the result on the console :
print(myVariable + myVariable2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Subtraction - :
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(myVariable - myVariable2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Multiplication * :
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(myVariable * myVariable2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Division / :
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(myVariable / myVariable2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/arithmetic?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Printing variables
&lt;/h2&gt;

&lt;p&gt;Previously we printed the result of the arithmetic operations directly using the print statement. But there’s a better way to do this; store the result in another variable.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;result = myVariable + myVariable2
print(result)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;You can also print the values of variables along with a print statement. Let me show you what I’m talking about. Run the code below.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("The result of addition is :",result)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/printingVariables?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;So instead of having just a number being printed in the console, we can have meaningful statements.&lt;/p&gt;

&lt;p&gt;You can also specify a particular place in the print statement where you want your variable to be printed.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("%s is the value of myVar!" % myVar)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Instead of the comma, we used after the string inside the print statement we use the ‘%’ here. ‘ %s’ is called a string literal which is used to specify the position inside a string where you want the value of a variable to be.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("The result of addition of %s and %s is : %s" % (myVar,myVar2,result))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Here we wanted to place multiple variables so, after the % add a parenthesis ( ) and mention the variables in the order you want them inside the print statement separated by a comma. Run the code below and see for yourself.&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/sPrinting?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Getting input from the user.
&lt;/h2&gt;

&lt;p&gt;Previously we assigned values to variables ourselves. Instead, we can get the value of the variable from the user. Here’s how :&lt;/p&gt;

&lt;p&gt;We use the input() statement. Equate the variable to an input statement. And inside the parathesis pass in your statement inside single quotes or double-quotes.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar = input("Enter the First Number : ")
myVar2 = input("Enter the Second Number : ")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;If you check the type of myVar and myVar2 it’s going to be .&lt;br&gt;
It’s because by default the type of the input function is a string. But we can perform mathematical calculations only on numbers. So to convert this to a number we do something called a ‘Type Casting’. We wrap the input statement inside an int(). This converts the string type to integer typer. If you want to work with decimals use float().&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar = int(input("Enter the First Number : "))
myVar2 = int(input("Enter the Second Number : "))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@Gothamv/inputFromUser?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;And there you have it! You’ve written your first piece of code that does something! We’ll learn more about programming and python in upcoming posts!&lt;/p&gt;

&lt;h3&gt;
  
  
  And that’s pretty much it for the basics.
&lt;/h3&gt;

</description>
      <category>python</category>
      <category>coding</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Learn the Basics of Git in Under 10 Minutes</title>
      <dc:creator>Gowtham Venkatesan</dc:creator>
      <pubDate>Sat, 13 Jul 2019 13:18:36 +0000</pubDate>
      <link>https://forem.com/gothamv/learn-the-basics-of-git-in-under-10-minutes-475c</link>
      <guid>https://forem.com/gothamv/learn-the-basics-of-git-in-under-10-minutes-475c</guid>
      <description>&lt;p&gt;Yes, the title is a clickbait. There is no way you can &lt;em&gt;understand&lt;/em&gt; the basics of git technology in just 10 minutes. But you can get pretty close in about 25 minutes. And that is the purpose of this article.&lt;/p&gt;

&lt;p&gt;If you want to get started on learning about Git technology, you’ve come to the right place. This is a comprehensive beginner’s guide to Git. There are many clients for Git. The technology is all the same no matter the client. But in this guide, we’ll be using GitHub to understand Git.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s get started!
&lt;/h3&gt;

&lt;h2&gt;
  
  
  What is Version Control?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. So ideally, we can place any file in the computer on version control.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Umm… Okay… But Why Tho?
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Here’s Why:
&lt;/h3&gt;

&lt;p&gt;A Version Control System (VCS) allows you to revert files back to a previous state, revert the entire project back to a previous state, review changes made over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more. Using a VCS also means that if you screw things up or lose files, you can generally recover easily. And sometimes you just want to know &lt;strong&gt;“who wrote this crap”&lt;/strong&gt;, and having access to that information is worthwhile 😈.&lt;/p&gt;

&lt;h2&gt;
  
  
  So What is Git?
&lt;/h2&gt;

&lt;p&gt;Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. Git is a &lt;strong&gt;&lt;em&gt;Distributed Version Control System&lt;/em&gt;&lt;/strong&gt;. So Git does not necessarily rely on a central server to store all the versions of a project’s files. Instead, every user “clones” a copy of a repository (a collection of files) and has the &lt;strong&gt;&lt;em&gt;full&lt;/em&gt;&lt;/strong&gt; history of the project on their own hard drive. This clone has &lt;em&gt;all&lt;/em&gt; of the metadata of the original while the original itself is stored on a self-hosted server or a third party hosting service like GitHub.&lt;/p&gt;

&lt;p&gt;Git helps you &lt;strong&gt;&lt;em&gt;keep track of the changes&lt;/em&gt;&lt;/strong&gt; you make to your code. It is basically the history tab for your code editor(With no incognito mode 🌚). If at any point while coding you hit a fatal error and don’t know what’s causing it you can always revert back to the stable state. So it is very helpful for debugging. Or you can simply see what changes you made to your code over time.&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F4912%2F1%2ALp_67l9zwur7aaFAhpVDrg.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%2Fcdn-images-1.medium.com%2Fmax%2F4912%2F1%2ALp_67l9zwur7aaFAhpVDrg.png" alt="A simple example of version history of a file."&gt;&lt;/a&gt;&lt;em&gt;A simple example of version history of a file.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the example above, all three cards represent different versions of the same file. We can select which version of the file we want to use at any point of time. So I can jump to and fro to any version of the file in the git time continuum.&lt;/p&gt;

&lt;p&gt;Git also helps you &lt;strong&gt;&lt;em&gt;synchronise code&lt;/em&gt;&lt;/strong&gt; between multiple people. So imagine you and your friend are collaborating on a project. You both are working on the same project files. Now Git takes those changes you and your friend made independently and merges them to a single “&lt;strong&gt;Master&lt;/strong&gt;” repository. So by using Git you can ensure you both are working on the most recent version of the repository. So you don’t have to worry about mailing your files to each other and working with a ridiculous number of copies of the original file. And collaborating long distance becomes as easy as HTML 🙃.&lt;/p&gt;

&lt;h2&gt;
  
  
  Git Workflow:
&lt;/h2&gt;

&lt;p&gt;Before we start working with Git commands, it is necessary that you understand what it represents.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Repository?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;repository&lt;/strong&gt; a.k.a. &lt;strong&gt;repo&lt;/strong&gt; is nothing but a collection of source code.&lt;/p&gt;

&lt;h3&gt;
  
  
  There are four fundamental elements in the Git Workflow.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Working Directory&lt;/strong&gt;, &lt;strong&gt;Staging Area&lt;/strong&gt;, &lt;strong&gt;Local Repository&lt;/strong&gt; and &lt;strong&gt;Remote Repository&lt;/strong&gt;.&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AiL2J8k4ygQlg3xriKGimbQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AiL2J8k4ygQlg3xriKGimbQ.png" alt="Diagram of a simple Git Workflow"&gt;&lt;/a&gt;&lt;em&gt;Diagram of a simple Git Workflow&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you consider a file in your Working Directory, it can be in three possible states.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;It can be staged.&lt;/strong&gt; Which means the files with the updated changes are marked to be committed to the local repository but not yet committed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;It can be modified&lt;/strong&gt;. Which means the files with the updated changes are not yet stored in the local repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;It can be committed&lt;/strong&gt;. Which means that the changes you made to your file are safely stored in the local repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;git add is a command used to add a file that is in the working directory to the staging area.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;git commit is a command used to add all files that are staged to the local repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;git push is a command used to add all committed files in the local repository to the remote repository. So in the remote repository, all files and changes will be visible to anyone with access to the remote repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;git fetch is a command used to get files from the remote repository to the local repository but not into the working directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;git merge is a command used to get the files from the local repository into the working directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;git pull is command used to get files from the remote repository directly into the working directory. It is equivalent to a git fetch and a git merge.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Now that we know what Git is and it’s basic terminologies, let’s see how we can place a file under git&lt;/strong&gt;. We’re going to do it the right way and the difficult way. Without any GUI applications.&lt;/p&gt;

&lt;p&gt;I’m assuming you already have a file you want to place under version control. If not create a sample folder named ‘MuskCult’ and place some sample code files in it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 0: Make a GitHub Account. Duh.
&lt;/h2&gt;

&lt;p&gt;If you don't already have one, you can make one &lt;a href="https://github.com/join" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Make sure you have Git installed on your machine.
&lt;/h2&gt;

&lt;p&gt;If you are on a &lt;strong&gt;Mac&lt;/strong&gt;, fire up the terminal and enter the following command:&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;This will prompt open an installer if you don’t already have git. So set it up using the installer. If you have git already, it’ll just show you which version of git you have installed.&lt;/p&gt;

&lt;p&gt;If you are running &lt;strong&gt;Linux&lt;/strong&gt;(deb), enter the following in the terminal:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install git-all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you are on &lt;strong&gt;Windows&lt;/strong&gt;:&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Just kidding… Relax… The number of people I triggered… Phew…&lt;br&gt;
Go to this &lt;a href="https://www.apple.com/macos/what-is/" rel="noopener noreferrer"&gt;link&lt;/a&gt; or this &lt;a href="https://gitforwindows.org/" rel="noopener noreferrer"&gt;link&lt;/a&gt; for more info on how to get it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Tell Git who you are.
&lt;/h2&gt;

&lt;p&gt;Introduce yourself. Slide in. Seriously, mention your Git username and email address, since every Git commit will use this information to identify you as the author.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git config --global user.name "YOUR_USERNAME"

$ git config --global user.email "im_satoshi@musk.com"

$ git config --global --list # To check the info you just provided
&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AJbyUdhLMEdglRxQk6PH7Vg.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AJbyUdhLMEdglRxQk6PH7Vg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Generate/check your machine for existing SSH keys. (Optional)
&lt;/h2&gt;

&lt;p&gt;Why you ask? Using the &lt;strong&gt;SSH protocol&lt;/strong&gt; , you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username or password at each visit.&lt;/p&gt;

&lt;p&gt;Follow this &lt;a href="https://help.github.com/articles/about-ssh/" rel="noopener noreferrer"&gt;link&lt;/a&gt; to learn more about SSH.&lt;br&gt;
Go &lt;a href="https://help.github.com/articles/checking-for-existing-ssh-keys/" rel="noopener noreferrer"&gt;here&lt;/a&gt; to check if you have an existing SSH key.&lt;br&gt;
Go &lt;a href="https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/" rel="noopener noreferrer"&gt;here&lt;/a&gt; to generate a SSH Key.&lt;br&gt;
Go &lt;a href="https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/" rel="noopener noreferrer"&gt;here&lt;/a&gt; to add the SSH key to your GitHub account.&lt;br&gt;
And finally, go &lt;a href="https://help.github.com/articles/testing-your-ssh-connection/" rel="noopener noreferrer"&gt;here&lt;/a&gt; to test its connection.&lt;/p&gt;

&lt;p&gt;If you did setup SSH, every git command that has a link you replace it by:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Instead of: https://github.com/username/reponame**

**You use    : git@github.com/username/reponame.git**

      **Note: You can use both ways alternatively**
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;I’ll be using SSH protocol in this tutorial.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Let’s Git
&lt;/h2&gt;

&lt;p&gt;Create a new repository on GitHub. Follow this &lt;a href="https://github.com/new" rel="noopener noreferrer"&gt;link&lt;/a&gt;.&lt;br&gt;
Now, locate to the folder you want to place under git in your terminal.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd Desktop/MuskCult
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Initialize Git:
&lt;/h3&gt;

&lt;p&gt;And to place it under git, enter:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ touch README.md   # To create a README file for the repository
$ git init          # Initiates an empty git repository
&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AQ_DUXRghgFQb9F47mUB6LQ.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AQ_DUXRghgFQb9F47mUB6LQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now go edit the README.md file to provide information about the repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add files to the Staging Area for commit:
&lt;/h3&gt;

&lt;p&gt;Now to add the files to the git repository for commit:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git add . 
# Adds all the files in the local repository and stages them for commit

OR if you want to add a specific file

$ git add README.md
# To add a specific file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Before we commit let’s see what files are staged:
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git status # Lists all new or modified files to be committed
&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Aa2_hw7cMe2R9R_aI86dB-A.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Aa2_hw7cMe2R9R_aI86dB-A.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Commit Changes you made to your Git Repo:
&lt;/h3&gt;

&lt;p&gt;Now to commit files you added to your git repo:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git commit -m "First commit"
# The message in the " " is given so that the other users can read the message and see what changes you made
&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ALoUwFy29RkgCS7hCajd_3g.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ALoUwFy29RkgCS7hCajd_3g.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Uncommit Changes you just made to your Git Repo:
&lt;/h3&gt;

&lt;p&gt;Now suppose you just made some error in your code or placed an unwanted file inside the repository, you can unstage the files you just added using:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git reset HEAD~1
# Remove the most recent commit
# Commit again!
&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ArxOX_U-ZRmGfhgIhNWlDIQ.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ArxOX_U-ZRmGfhgIhNWlDIQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Add a remote origin and Push:
&lt;/h3&gt;

&lt;p&gt;Now each time you make changes in your files and save it, it won’t be automatically updated on GitHub. All the changes we made in the file are updated in the local repository. Now to update the changes to the master:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git remote add origin remote_repository_URL
# sets the new remote
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;strong&gt;git remote&lt;/strong&gt; command lets you create, view and delete connections to other repositories.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git remote -v
# List the remote connections you have to other repositories.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;strong&gt;git remote -v&lt;/strong&gt; command lists the URLs of the remote connections you have to other repositories.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push -u origin master # pushes changes to origin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now the &lt;strong&gt;git push&lt;/strong&gt; command pushes the changes in your local repository up to the remote repository you specified as the origin.&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Aw-nfopsKIks_JRzFe5D8xA.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Aw-nfopsKIks_JRzFe5D8xA.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now if we go and check our repository page on GitHub it should look something like this:&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F4080%2F1%2AaQljQFkytY84BgmlVtpgmw.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%2Fcdn-images-1.medium.com%2Fmax%2F4080%2F1%2AaQljQFkytY84BgmlVtpgmw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that’s it. You’ve just added the files to the repository you just created on GitHub.&lt;/p&gt;

&lt;h3&gt;
  
  
  See the Changes you made to your file:
&lt;/h3&gt;

&lt;p&gt;Once you start making changes on your files and you save them, the file won’t match the last version that was committed to git. To see the changes you just made:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git diff # To show the files changes not yet staged
&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Axym1QvvvWorfoyGMXv28Yg.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Axym1QvvvWorfoyGMXv28Yg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Revert back to the last committed version to the Git Repo:
&lt;/h3&gt;

&lt;p&gt;Now you can choose to revert back to the last committed version by entering:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout .

OR for a specific file

$ git checkout -- &amp;lt;filename&amp;gt;
&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AHYgYkfo3W4MUA8CJl12rXg.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AHYgYkfo3W4MUA8CJl12rXg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  View Commit History:
&lt;/h3&gt;

&lt;p&gt;You can use the &lt;strong&gt;git log&lt;/strong&gt; command to see the history of commit you made to your files:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git log
&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A9w7uBJcQMxc708DBw8Sewg.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A9w7uBJcQMxc708DBw8Sewg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each time you make changes that you want to be reflected on GitHub, the following are the most common flow of commands:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git add .
$ git status # Lists all new or modified files to be committed
$ git commit -m "Second commit"
$ git push -u origin master
&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ArWBJnBdF1V8YO_mi-jEfxA.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ArWBJnBdF1V8YO_mi-jEfxA.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if we go and see our repo, we can identify whether the commit was successful by looking at the commit message for each file.&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F4216%2F1%2AQHM8m5HGavHkdzPz06UWGw.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%2Fcdn-images-1.medium.com%2Fmax%2F4216%2F1%2AQHM8m5HGavHkdzPz06UWGw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: That’s all well and good… But How do I download and work on other repositories on GitHub?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Cloning a Git Repo:
&lt;/h3&gt;

&lt;p&gt;Locate to the directory you want to clone the repo. Copy the link of the repository you want and enter the following:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone remote_repository_URL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Feel free to go ahead and clone the repo I created above using: &lt;a href="https://github.com/Gothamv/MuskCult" rel="noopener noreferrer"&gt;https://github.com/Gothamv/MuskCult&lt;/a&gt;&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A6NACk8-IiBjbauM-k-aesQ.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A6NACk8-IiBjbauM-k-aesQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Pushing Changes to the Git Repo:
&lt;/h3&gt;

&lt;p&gt;Now you can work on the files you want and commit to changes locally. If you want to push changes to that repository you either have to be &lt;a href="https://help.github.com/articles/inviting-collaborators-to-a-personal-repository/" rel="noopener noreferrer"&gt;added as a collaborator&lt;/a&gt; for the repository or you have to create something known as a pull request. Go and check out how to do one &lt;a href="https://help.github.com/articles/creating-a-pull-request/" rel="noopener noreferrer"&gt;here&lt;/a&gt; and give me a pull request with your code file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Collaborating:
&lt;/h3&gt;

&lt;p&gt;So imagine you and your friend are collaborating on a project. You both are working on the same project files. Each time you make some changes and push it into the master repo, your friend has to pull the changes that you pushed into the git repo. Meaning to make sure you’re working on the latest version of the git repo each time you start working, a git pull command is the way to go.&lt;/p&gt;

&lt;p&gt;Now below is an example of a project my friend and I are collaborating on:&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F4216%2F1%2A2-tl2rHsgPqiv88aI55CPw.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%2Fcdn-images-1.medium.com%2Fmax%2F4216%2F1%2A2-tl2rHsgPqiv88aI55CPw.png" alt="There has just been a commit on the repo"&gt;&lt;/a&gt; &lt;strong&gt;There has just been a commit on the repo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So to make sure those changes are reflected on my local copy of the repo:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git pull origin master
&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AySDKu2OEdkc26yOUp-TJJQ.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AySDKu2OEdkc26yOUp-TJJQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Here’s two more useful git commands:
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git fetch
    AND
$ git merge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the simplest terms, git fetch followed by a git merge equals a git pull. But then why do these exist?&lt;/p&gt;

&lt;p&gt;When you use git pull, Git tries to automatically do your work for you. &lt;strong&gt;It is context sensitive&lt;/strong&gt;, so Git will merge any pulled commits into the branch you are currently working in. git pull &lt;strong&gt;automatically merges the commits without letting you review them first&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When you git fetch, Git gathers any commits from the target branch that do not exist in your current branch and &lt;strong&gt;stores them in your local repository&lt;/strong&gt;. However, &lt;strong&gt;it does not merge them with your current branch&lt;/strong&gt;. This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files. To integrate the commits into your master branch, you use git merge.&lt;/p&gt;

&lt;h2&gt;
  
  
  One More Thing:
&lt;/h2&gt;

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

&lt;/div&gt;

&lt;p&gt;So what is it?&lt;/p&gt;

&lt;p&gt;.gitignore tells git which files (or patterns) it should ignore. It's usually used to avoid committing transient files from your working directory that aren't useful to other collaborators, such as compilation products, temporary files IDEs create, etc.&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F2914%2F1%2A3NFtOjfz0NvNSwba7YCmDA.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%2Fcdn-images-1.medium.com%2Fmax%2F2914%2F1%2A3NFtOjfz0NvNSwba7YCmDA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So in the above example, files like &lt;strong&gt;pycache&lt;/strong&gt;, .DS_Store are used by the system to store information for faster access. This is not useful for other collaborators. So we can tell git to ignore them by adding a .gitignore file.&lt;/p&gt;

&lt;p&gt;Use the touch command to create the .gitignore file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ touch .gitignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And you can add the following patterns to tell git to ignore such files.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/&lt;em&gt;.cmake&lt;br&gt;
/&lt;/em&gt;.DS_Store&lt;br&gt;
/.user&lt;br&gt;
/build&lt;br&gt;
etc. depending upon the files you want git to untrack&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  And that’s pretty much it for the basics. Stay tuned for Part 2 which will focus on Branch, Merge, Stash, Rebase etc.&lt;br&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Peace Out ✌️
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/" rel="noopener noreferrer"&gt;https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.github.com/2015-06-08-how-to-undo-almost-anything-with-git/" rel="noopener noreferrer"&gt;https://blog.github.com/2015-06-08-how-to-undo-almost-anything-with-git/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dont-be-afraid-to-commit.readthedocs.io/en/latest/git/commandlinegit.html" rel="noopener noreferrer"&gt;https://dont-be-afraid-to-commit.readthedocs.io/en/latest/git/commandlinegit.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.gitlab.com/ee/gitlab-basics/start-using-git.html" rel="noopener noreferrer"&gt;https://docs.gitlab.com/ee/gitlab-basics/start-using-git.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/292357/what-is-the-difference-between-git-pull-and-git-fetch" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/292357/what-is-the-difference-between-git-pull-and-git-fetch&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/3a2x1iJFJWc" rel="noopener noreferrer"&gt;https://youtu.be/3a2x1iJFJWc&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
