I will start this Python Tutorial by giving you enough reasons to learn Python. Python is simple and incredibly readable since closely resembles the English language. Through this Python Tutorial, I will introduce you to each aspect of Python and help you understand how everything fits together to gain insights from it.
- Hello World Program
- Python & It’s Features
- Python Applications
- Variables
- Data types
- Operators
- Conditional Statements
- Loops
- Functions
- Hello World Program:
Python is a great language for beginners, all the way up to seasoned professionals. In Python, you do not have to deal with complex syntax’s, let me give you an example:
If I want to print Hello World in Python.
- Python & It’s Features:
Python is an open source scripting language which was created by Guido van Rossum in 1989. It is an interpreted language with dynamic semantics and is very easy to learn. Let’s look at some cool features of Python.
- 1. Open source General purpose Language.
- 2. Automatic Memory Management.
- 3. Supports variety of Basic DataType.
- 4. Great Interactive Environment
- 5. Supports Objects Oriented Programming.
- 6. Python runs On all Major Operating Systems.
- Python Applications:
Python finds application in a lot of domains, below are few of those:
- 1. Web Scraping
- 2. Testing
- 3. Web Development
- 4. Data Analysis
- Variables in Python:
Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
Assigning values to a variable:
Python variables do not need an explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.
- Data Types in Python:
Python supports various data types, these data types define the operations possible on the variables and the storage method. Below is the list of standard data types available in Python:
- 1. Numeric
- 2. List
- 3. Tuple
- 4. String
- 5. Set
- 6. Dictionary
- Operators in Python:
Operators are the constructs which can manipulate the values of the operands. Consider the expression 2 + 3 = 5, here 2 and 3 are operands and + is called operator.
Python supports the following types of Operators:
- 1. Arithmetic Operators
- 2. Comparison Operators
- 3. Assignment Operators
- 4. Bitwise Operators
- 5. Logical Operators
- 6. Membership Operators
- 7. Identity Operators
- Conditional Statements:
Conditional statements are used to execute a statement or a group of statements when some condition is true. There are namely three conditional statements .
- 1. If
- 2. Elif
- 3. Else.
Let me tell you how it actually works.
First, the control will check the ‘If’ condition. If its true, then the control will execute the statements after If condition.
When ‘If’ condition is false, then the control will check the ‘Elif’ condition. If Elif condition is true then the control will execute the statements after Elif condition.
If ‘Elif’ Condition is also false then the control will execute the Else statements.
- Loops:
In general, statements are executed sequentially. The first statement in a function is executed first, followed by the second, and so on
There may be a situation when you need to execute a block of code several times
A loop statement allows us to execute a statement or group of statements multiple times. The following diagram illustrates a loop statement:
Let me explain you the above diagram:
First, the control will check the condition. If it is true then the control will move inside the loop and execute the statements inside the loop.
Now, the control will again check the condition, if it is still true then again it will execute the statements inside the loop.
This process will keep on repeating until the condition becomes false. Once the condition becomes false the control will move out of the loop.
There are two types of loops:
- Infinite: When the condition will never become false.
- Finite: At one point, the condition will become false and the control will move out of the loop
There is one more way to categorize loops:
- Pre-test: In this type of loops the condition is first checked and then only the control moves inside the loop
- Post-test: Here first the statements inside the loops are executed, and then the condition is checked.
Python does not support Post-test loops.
- Loops in Python:
In Python, there are three loops:
- 1. While
- 2. For
- 3. Nested
- Functions:
Functions are a convenient way to divide your code into useful blocks, allowing us to order our code, make it more readable, reuse it and save some time.