Python beginner course
Hello Readers!
Today we are going to learn Python in just a one blog. This article will make you familiar to Python coding and its concepts. This blog is going to help you as Python beginner course as you will learn Python basics here.
First is first, we must install Python in our system before starting learning it. We have two options to install Python into our system.
- Install Python – It is Python scripting setup
- Install Anaconda Package – It is more advance Python setup with covers various data analysis and data science libraries. We have two editors/IDE (Jupyter Notebook and Spyder) as well which are used in organizations while working in project.
My Recommendation is to download and Install Anaconda package in your system instead of Python only. You can download anaconda package from anaconda site https://www.anaconda.com/. I am not adding direct link because time to time direct link keep changing. Mainly you need to type download anaconda in google and then download Windows (64 or 32 bit) or Ubuntu or Mac setup as per your system. You can watch below video to setup anaconda in your system.
Coding in Python
We start learning Python with Python Scripting as Python beginner course therefore this article will first cover the Python basics which are part of Python Training for beginners. We will start learning Python with Jupyter Notebook IDE. You can open Jupyter Notebook editor from your system by going to Start Menu then go to Anaconda Folder then select Jupyter Notebook. This will open one black cmd window and then you will see Jupyter Notebook open in browser automatically. Then click on new and select Python option from dropdown. It will open new Python Jupyter Notebook editor where you can try your codes. You can follow above video to open Python Jupyter Notebook editor.
Python variables
Variable are smallest object in any programming language which holds single value like integer, string, date, float etc. You can create object in Python by assigning any value to some name with equals sign (=).
Object_Name = some_value
Above line contains 3 parts.
- Object_Name – It is the name of object which will hold the value
- = – It is used to assign value to Object_Name
- Some_value is the value which we are assigning to object
By following above syntax, we can try to create multiple objects as below. Copy and Paste below lines into Jupyter Notebook and press Ctrl + Enter keys together from your keyboard. It will run code and create below three objects in Python environment.
# Below line will create object with name int_obj and it will hold value as 10
int_obj = 10
# Below line will create object with name float_obj and it will hold value as 10.5
float_obj = 10.5
# Below line will create object with name string_obj and it will hold value as My first character object
string_obj = "My first char object"
Note: values other than integer and float must be enclosed withing either single quotes like 'Vikas' or double quotes like "Vikas"
Now you may have noticed that there are 3 lines in above code which start with #. What does lines start with hash (#) means? These are comments. If you want to add comment code explanatory text into you code then you can add any text and apply # at starting of line. This way code will ignore those lines.
Python Lists
In above section, we learnt to create single value object. Now question comes how we can create multiple values objects in Python. We Python List where we can assign multiple values to single object. Python Lists are equivalent to array in other programming language. Best thing above Python list is that Python list can hold any type of data unlike array. Python list hold values based on index and first index start with 0 and goes to n-1.
Let’s try to create Python lists. Python list can be created by enclosing multiple values in square brackets.
# Below line of code will create Python list object which will hold values as 11, 12, 13, 14 and 15. All values assigned to Age list object is type of integer only.
Age = [11, 12, 13, 14, 15]
# Let’s create list with different types of values. Below code is creating list object with name person_details which holds 3 values Sandy, 27 and 898-989-8989.
person_details = ["Sandy", 27, "898-989-8989"]
Interpreting Lists
Age list object is created with values 11, 12, 13, 14 and 15 therefore we can say that Age list object contains 5 elements. You can check this by running below code
len(Age)
Above line will give you result as 5. As we know that Python list objects save values/elements based on index and index starts from 0 therefore we can say that 11 is saved at 0 index, 12 is saved at 1 index and 13 is saved at 2 index and so on.
person_details list object also contains 3 objects which are saved at 0, 1 and 2 index position.
How to extract values from Python list?
As we have discussed Python list objects save values/elements based on index methodology starting from 0 therefore we can extract/fetch value from list objects using index values only.
To extract values from list, we need to follow below syntax.
listname[index_number]
Age[0] #will give us value saved at 0 index and that value is 11.
Age[3] # will give us value saved at 3 index which is 4th value because index starts from 0 and that value is 14
Note: let me give you one quick exercise to you. You need to extract 15 from Age list. Now you need to think which index element value 15 is. You need to give Age[index_15_value] to extract value 15 from Age list object.
How to extract multiple values from Python List?
You can also extract multiple values from Python list by using colon as below.
List[start_index:end_index]
Start index is inclusive and End index is exclusive.
Suppose we have Age list object created with 5 elements starting from 0 to 4 then if we want to extract 12,13,14 then we need to write below syntax
Age[1:4]
Let me tell you how I have written above code Age[1:4] to extract 12, 13 and 14. As we know that 11 is saved at 0 index, 12 is saved at 1 index, 13 is saved at 2 index, 14 is saved at 3 index and 15 is saved at 4 index.
Now to extract 12, 13 and 14 we need to give starting and ending index of 12 to 14 but as we know that ending index is exclusive and list will not give the value of ending index therefore we need to get one index ahead of value 14 therefore we will have to give the index of 15 and as per rule it will be excluded from result.
You can continue learning more in below Python beginner course session. It cover Python basics for beginners.
More related topics
Python career path introduction
Comparison of Data Analyst vs Data Scientist vs Data Visualization
Comparison of SAS, R and Python
Complete introduction to Machine Learning step by step
Introduction to Time Series Forecasting
You can download code discussed during session.
Tag: Python beginner course, Python free training, Python free course online, Python online course free, Python basics
Description: Python beginner course, Python free training, Python free course online, Python online course free, Python basics
Topic: Python
Category: Python
Click to download working files and code 'Code_discussed_during_session.py'