PYTHON 101
Tags: programming, python
Published: 2022-02-13 17:19:54

The best way to learn a programming language is to do as much practice as you can. Well, maybe you are wondering how do I go about it, it is simple. You can install python onto your machine or you can still practice by using many of the online interpreter such as; https://www.python.org/shell/ or https://replit.com/languages/python3 just to mention a few. With that out of the way let us dive into the python basic shall we?

## **The Basics**

```
------Table of contents------
Basic Python Introduction
Variables
Operators
Data Type
Comments
```

### **Basic Python Introduction**

In any programming language there is a set of rules that one has to follow so that we can tell a computer what to do. This set of rules are called _**syntax**_. It is super important to learn and use the correct syntax when writing code else will fall into an error called _syntax error_ and the code will not execute at all.
Also to note, aside from the syntax, we have **_semantics_** which is basically the overall effect that the code has. It is possible to to have code that is in the correct format but does not do what we want it to do and this is an example of a _semantic error_.

## **Variables**
Think of variables as containers that we use when we ask a computer to perform an operation for us. Variables come in handy when we need to store values for later reference. When we create a variable, the computer reserves a portion of its own memory to store the value, allowing the computer to read or edit the value later when need be.
Let us have a look at this simple script that calculate the sum of two numbers.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aogj65mex47cg5q4mix8.png)
From the above code snippet, we assign the first number variable to five and the second  number variable to ten. The process of storing a value inside a variable is called _assignment_. We assign the sum of the numbers with the result of the expression of first number added to second number. This is known as an _expression_.

## **Operators**
Operators perform operation on variables. For instance we can use * operator to multiply two numbers.
In python, the commonly used operators are:

1. Arithmetic operator: They are used to perform common mathematical operation and they are;`+ => Addition
          - => Subtraction
          * => Multiplication
          / => Division 
          ** => Exponentiation
          // => Floor Division
          % => Modulus
`
2. Assignment Operators: They are used to assign values to variables. They include;
`= example is x = 10
 += example x+=10 is the same as x = x+10
 -= example x-=10 is the same as x = x-10 *= example x*=10 is the same as x = x*10
 /= example x/=10 is the same as x = x/10 
%= example x %= 10 is the same as x = x%10 etc.`
3. Comparison operators are used to compare two values. They include;
        == which is Equal 
        != It means not equal to
        > means greater than
        < means less than
        >= Greater than or equal to
      <= Less than or equal to.`
The following code snippet shows the above comparison operators.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d8uupgij9i6vlx2m3tar.png)
 
4. Logical Operators are used during combination of conditional statements.
Logical operators in python include;

1. and which returns true if both condition is true
2. or return True if one of the statements is true.
3. not negates or gives a reverse of the result that is if True it returns False and vice versa.
Below is a code snippet to illustrate the concept discussed.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e7hq13s635imu5mtn2po.png)

## **Comments**
Comment are statements in Python that cannot be executed. Comments are crucial while writing code for they help us and others understand the code we write. In python single line comments are written starting with a hash character followed by the text we want commented.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3r7m8hhtb1nbxixrrxc.png)
For multiline comments we use triple quotation(''').
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d07sdp67yl6oegfr4lwv.png)
  
## **Data Types**
In programming, data types play such a crucial part. Variables tend to store data in different types where the different types tend to do different things.
Just for reference when you want to know the  what is the data type of a variable, we use a type() function which returns the object type.
In Python, the most commonly used data types are:
1. strings: This is written text between quotes eg "Hello World!".

2. Integer: This are whole numbers without a fraction i.e. 120, 1, 10.

3.Float: This represents real numbers or numbers with a fraction bit in them eg 2.8, 10.5 etc.

4.Boolean:This types of data type may have one of the two values; _True_ or _False_
The code snippet illustrates the data types discussed above.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqtbagftzp4ekx4x5k92.png)
For more additional materials, please feel free to look at the following;
Python Documentation https://docs.python.org/3/
W3school Python https://www.w3schools.com/python/default.asp