Python Tutorial For Beginners - Learn Python Programming Language Basics - Intellipaat
Python Tutorial For Beginners - Learn Python Programming Language Basics - Intellipaat
By Naveen
Introduction to Python
In this python tutorial we will comprehensively learn all the concepts of Python. Let’s start
o by understanding what exactly is Python.
Python is a free, open source programming language. So, all you have to do is install
Python once and you can start working with it. And since Python is open source, you can
contribute your own code to the community.
Python is also a cross platform compatible language. So, what does this mean? Well, you
can install and run Python on several operating systems. So, whether you have a Windows,
Mac or Linux, you can be rest assured that Python will work on all these operating systems.
https://intellipaat.com/blog/tutorial/python-tutorial/ 1/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Python is also a great visualization tool. Python provides libraries such as matplotlib,
seaborn and bokeh to create stunning visualizations.
Python is the most popular language for implementing machine learning and deep
learning tasks. Today, every top organization is investing in the eld of machine learning
and majority of these machine learning applications are implemented with python at back-
end.
Now, that we have understood what exactly is python, let us go ahead in this Python
tutorial and understand why should we learn python?
https://intellipaat.com/blog/tutorial/python-tutorial/ 2/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Learning python programming language is fun. If you compare python with any other
language for example java or c++, you’ll nd that it’s syntax is way lot easier. You also don’t
have to worry about the missing semi colons(;) in the end.
Let’s say we want to print “Welcome to the world of programming.” on our screen. Now,
let’s compare the syntax for python and java:
Python Syntax:
print(“Welcome to the world of programming”)
Java Syntax:
class Simple{
So, here we see that, python code is of just one line but when it comes to java, there are
multiple lines of code just for printing a statement.
https://intellipaat.com/blog/tutorial/python-tutorial/ 3/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Career Opportunities:
Python has huge career opportunities in the IT industry. Almost every other IT company, be
it a startup or a Multi-National Company uses python for varied applications. So, if you
have good expertise in python, you will be in demand for a wide range of jobs in di erent
domains such machine learning, cloud infrastructure, web-site designing, testing and many
more.
Watch this Python for Data Science Video:
Let’s say you are working on a python project and you get stuck somewhere, you don’t
have to worry at all because python has a huge community for help. So, if you have any
queries, you can directly seek help from millions of python community members.
Now, in this python tutorial, we will look at the procedure to install python.
Python Installation
If you are new to programming, then installing a programming language itself could be a
herculean task. So, now we are going to look at the step by step process to install python.
1. Start o by going to this website -> https://www.python.org/downloads/
(https://www.python.org/downloads/)
https://intellipaat.com/blog/tutorial/python-tutorial/ 4/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
2. Click on the downloads tab and choose the operating system and python version. So,
here I am downloading python version 3.7.4 for Windows operating system.
Now that we have installed python, let’s go ahead in this python tutorial and start o with
programming in Python
For the best of career growth, check out Intellipaat’s Python Course in Sydney (https://intellipaat.co
m/python-certi cation-training-online-sydney/) and get certi ed!
Variables in Python:
You can consider a variable to be a temporary storage space where you can keep changing
values. Let’s take this example to understand variables:
So, let’s say, we have this cart and initially we store an apple in it.
https://intellipaat.com/blog/tutorial/python-tutorial/ 5/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
After a while, we take out this apple and replace it with a banana.
https://intellipaat.com/blog/tutorial/python-tutorial/ 6/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
So, here this cart acts as a variable, where the values stored in it keep on changing.
Now, that we have understood what a variable is, let’s go ahead and see how can we assign
values to a variable in python.
Watch this Python Interview Questions video:
To assign values to a variable in Python, we will use the assignment (=) operator.
Here, initially, we have stored a numeric value -> 10 in the variable ‘a’. After a while, we
have stored a string value -> “sparta” in the same variable. And then, we have stored the
logical value True.
Now, let’s implement the same thing in Jupyter Notebook and look at the result:
Assigning a value 10 to a:
Assigning “sparta” to a:
https://intellipaat.com/blog/tutorial/python-tutorial/ 7/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Assigning True to a:
Going ahead in this python tutorial, we will learn about data types in Python..
Now, let’s understand these individual data types by their implementation in jupyter
notebook.
Watch this Matplotlib Python Tutorial Video for Beginners:
https://intellipaat.com/blog/tutorial/python-tutorial/ 8/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Numbers in Python
Numbers in python could be integers, oating point numbers or complex numbers.
Here, we have assigned the value 100 to num1 and when we check the type of the variable,
we see that it is an integer.
This time, we have assigned the value 13.4 to num2 and checking the type of the variable,
tells us that it is oat.
Here, we have assigned the value 10-10j to num3. Now 10-10j comprises of two parts-> the
real part and the imaginary part and combining these two gives us the complex number.
https://intellipaat.com/blog/tutorial/python-tutorial/ 9/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Python Strings
Anything written in single or double quotes is treated as a string in Python.
Now, let’s see how can we extract individual characters from a string.
So, I’d want to extract the rst two characters from ‘str1’ which I have created above:
Now, similarly, let’s extract the last two characters from str1:
https://intellipaat.com/blog/tutorial/python-tutorial/ 10/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Python Tuples
A python tuple is a collection of immutable python objects enclosed within parenthesis ().
Elements in a tuple could be of same data type or of di erent data type.
Python Lists
A Python Lists (https://intellipaat.com/blog/tutorial/python-tutorial/python-lists/) is an ordered
collection of elements.
https://intellipaat.com/blog/tutorial/python-tutorial/ 11/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
The below line of code will return the length of the list:
https://intellipaat.com/blog/tutorial/python-tutorial/ 12/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Python Sets
Python sets (https://intellipaat.com/blog/tutorial/python-tutorial/python-sets/) are collection of
unordered and unindexed items.
Sets can be used to perform mathematical calculations such as union, intersection and
di erences.
Creating a set:
Here, in set ‘Age’, value “22” is appearing twice. Since, every element in set is unique, it will
remove the duplicate value.
Operations on Sets:
1.add : This method adds element to the set if it is not present in it.
https://intellipaat.com/blog/tutorial/python-tutorial/ 13/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
4.di erence: The di erence of two sets(set1, set2) will return the elements which are
present only in set1.
Python Dictionary
https://intellipaat.com/blog/tutorial/python-tutorial/ 14/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Creating a Dictionary:
Going ahead in this python tutorial, we will learn about conditional statements.
https://intellipaat.com/blog/tutorial/python-tutorial/ 15/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Conditional Statements
Conditional statements are used for running a line of code or set of code if it satis es a
particular condition. A particular condition is provided, if it is true the code will execute
otherwise the control will be passed on to next control statement.
There are three types of conditional statements as illustrated in the above example:
1.If statement: Firstly, “if” condition is checked and if it is true the statements under “if”
statements will be executed. If is false then the control will be passed on to the next
conditional statements.
2.Elif statement: If the previous condition is false, either it could be “if” condition or “elif”
after “if”, then the control is passed on to the “elif” statements. If it is true then the
statements after “elif” condition will execute. There can be more than one “elif” statements.
3.Else statement: When “if” and “elif” conditions are false, then the control is passed on to
the “else” statement and it will execute.
Now, let’s go ahead and learn about loops in this python tutorial.
https://intellipaat.com/blog/tutorial/python-tutorial/ 16/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Loops
If we have a block of code then statements in it will be executed sequentially. But, when we
want a statement or a set of statements to be executed multiple times then we use loops.
Types of loops:
1.While loop: We use this loop when we want a statement or a set of statement to execute
as long as the Boolean condition associated with it satis es.
In while loop, the number of iterations depends on the condition which is applied to the
while loop.
2.for loop: Here, we know the number of iterations unlike while loop. This for loop is also
used for iterations of statements or a set of statements multiple times.
https://intellipaat.com/blog/tutorial/python-tutorial/ 17/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
3.nested loop: This type of loop consists of loop inside a loop. It can be for loop or can be a
combination of for and while loop.
Now, we will learn about user-de ned functions in this python tutorial.
https://intellipaat.com/blog/tutorial/python-tutorial/ 18/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
In any programming language, functions are a better and systematic way of writing.
Functions provide us the liberty to use the code inside it whenever it is needed just by
calling the function by it’s name.
Going ahead in this Python tutorial, we will learn about Exception Handling.
Exception Handling
Basically, an exception is an abnormal condition or error that occurs during the execution
of a program. Whenever an exception occurs in a program, the execution of the program
halts, and the further instruction of the programs are not executed.
We need to handle these exceptions in order to ensure the normal execution of the
program.
Some of the common exceptions that occur in Python programs while executing are:
1. NameError: This error occurs when a name is not found.
2. ZeroDivisionError: When a number is divided by zero, ZeroDivisionError occurs.
3. IndentationError: This error occurs due to wrong indentation.
4. IOError: When Input Output operation fails, IOError occurs.
So, in Python we use try, catch, except and nally to handle the exceptions.
try-except block
In Python program, the line of code that may throw exceptions are placed in try block.
The try block should have except block with it to handle the exception. If any exception
occurs in try block then the statements in except block will be executed.
https://intellipaat.com/blog/tutorial/python-tutorial/ 19/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Syntax:
try:
#line of code
except Exception:
#line of code
Example:
https://intellipaat.com/blog/tutorial/python-tutorial/ 20/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
else block
In this case, the else block will be executed if no exception occurs.
Syntax:
try:
#line of code
except Exception:
#line of code
else:
Example:
https://intellipaat.com/blog/tutorial/python-tutorial/ 21/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
nally block
If we want a piece of code which cannot be skipped and it has to be executed under any
circumstances, then we put that piece of code in nally block.
Syntax:
try:
#line of code
finally:
Example:
https://intellipaat.com/blog/tutorial/python-tutorial/ 22/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Here, in this tutorial we learnt all the basics of Python which are variables, string, numbers,
data types, tuples, lists, sets, dictionary, conditional statements, loops, user de ned
functions and exception handling. If you want to go through more concepts of Python in
depth, this Python Tutorial consists of all the modules which will help you throughout your
learning.
Kick-start your career in Python with the perfect Python Course in New York (https://intellipaat.co
m/python-certi cation-training-online-new-york/) now!
Next (https://intellipaat.com/blog/tutorial/python-tutorial/fundamentals-of-python/)
Table of Contents
Fundamentals of Python
Python Fundamentals: Fundamentals of Python consists of discussion of basic building
blocks of Python programming language. Here, “Fundamentals of Python” is divided into
the following categories. And we will be discussing each topic separately. Statements
Expressions Assignment Statements Indentations Comments Single-line comments Multi-
line comment doc-staring comments Variables Constants Tokens Identi ers Keywords
Literals Operators Watch this Python Pandas Tutorial Video for Read More (https://intellipaat.c
om/blog/tutorial/python-tutorial/fundamentals-of-python/)
What is Python?
What is Python?
Python is a high-level, general-purpose programming language with an elegant syntax that
allows programmers to focus more on problem-solving than on syntax errors. One of the
primary goals of Python Developers is keeping it fun to use. Python has become a big buzz
https://intellipaat.com/blog/tutorial/python-tutorial/ 24/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Python Version
Python History
Lets start o by looking at Python history. Python was developed at a time when many
other dynamic and open-source programming languages like Tcl, Perl, Ruby etc. were also
being actively developed and gaining popularity. Watch this Python Projects Video for
Beginners: [videothumb class="col-md-12" id="g6iVdilJNMQ" alt="Python Tutorial"
title="PythonTutorial"] The below-given image depicts the python logo then vs Python Read
More (https://intellipaat.com/blog/tutorial/python-tutorial/python-version/)
Python Syntax
Comments in Python
Comments in Python
In this module of Python tutorial, we will learn about Python comments. We will also learn
about the di erent types of Python comments and the way to use them. Writing Python
Comments Comments in any programming language are used to increase the readability
of the code. Similarly, in Python, when the program starts getting complicated, one of Read
More (https://intellipaat.com/blog/tutorial/python-tutorial/python-comments/)
Numbers in Python
Numbers in Python
In Python, the number data type is used to store numeric values. are an immutable data
type. Being an immutable data type means that if we change the value of an already
allocated number data type, then that would result in a newly allocated object. In this
module, we will delve deeper into the Read More (https://intellipaat.com/blog/tutorial/python-tuto
rial/python-numbers/)
String in Python
Python Lists
List in Python
Lists are Python’s most exible ordered collection object type. It can also be referred to as
a sequence that is an ordered collection of objects that can host objects of any data type,
such as Python Numbers, Python Strings and nested lists as well. Lists are one of the most
https://intellipaat.com/blog/tutorial/python-tutorial/ 26/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
used and versatile Python Data Types. In this Read More (https://intellipaat.com/blog/tutorial/pyt
hon-tutorial/python-lists/)
Tuple in Python
Python Sets
Set in Python
A set in Python is mutable, iterable, and does not have any duplicate elements. It is an
unordered collection of elements which means that a set is a collection that stores
elements of di erent Python Data Types. Remember that a set in Python doesn’t index the
elements in a particular order. Let us look at some of Read More (https://intellipaat.com/blog/tut
orial/python-tutorial/python-sets/)
Python Dictionary
Dictionary in Python
Python dictionary is yet another unordered collection of elements. The di erence between
Python dictionary and other unordered Python data types such as sets lies in the fact that
unlike sets, a dictionary contains keys and values rather than just elements. Like lists,
Python dictionaries can also be changed and modi ed, but unlike Python lists the values in
Read More (https://intellipaat.com/blog/tutorial/python-tutorial/python-dictionary/)
Python Operators
Operators in Python
In Python, we have a set of special symbols that perform various kinds of operations such
as logical operations, mathematical operations, and more. These symbols are called
Python operators. For every symbol or operator, there is a unique kind of operation. The
values on which the operators perform their respective operations are known as operands.
In this Read More (https://intellipaat.com/blog/tutorial/python-tutorial/python-operators/)
https://intellipaat.com/blog/tutorial/python-tutorial/ 27/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
The process of converting a Python data type into another data type is known as type
conversion. There are mainly two types of type conversion methods in Python, namely,
implicit type conversion and explicit type conversion. Watch this video on Python:
[videothumb class="col-md-12" id="e9p0_NB3WrM" alt="Python Tutorial"
title="PythonTutorial"] In this module, we will go through Read More (https://intellipaat.com/blo
g/tutorial/python-tutorial/type-conversion-in-python/)
Python Functions
Functions in Python
Functions are used to group together a certain number of related instructions. These are
reusable blocks of codes written to carry out a speci c task. A function might or might not
require inputs. Functions are only executed when they are speci cally called. Depending on
https://intellipaat.com/blog/tutorial/python-tutorial/ 28/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
the task a function is supposed to carry out, it might or might Read More (https://intellipaat.co
m/blog/tutorial/python-tutorial/python-functions/)
(https://intellipaat.com/python-certi cation-training-online/)
Built in Functions in Python Back in the Python Functions module, we learnt that there are
three types of functions, namely, user-de ned functions in Python, lambda functions in
Python, and built in functions in Python. In this module, we will learn all that we need to
know about built in functions in Python. So, without further ado, let’s get started. Read More
(https://intellipaat.com/blog/tutorial/python-tutorial/python-built-in-functions/)
Python Arrays
https://intellipaat.com/blog/tutorial/python-tutorial/ 29/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Python is an object-oriented language and almost every entity in Python is an object, which
means that programmers extensively use classes and objects while coding in Python.
Objects in Python are basically an encapsulation of Python variables and functions, that
they get from classes. Watch this video on ‘Python Classes and Objects’: [videothumb
class="col-md-12" id="c4EG6O299tY" Read More (https://intellipaat.com/blog/tutorial/python-tutori
al/python-classes-and-objects/)
Python Modules
Modules in Python
When we write a program in Python Interpreter or Python Shell and then exit from Shell, all
de nitions that we have included in our program get lost. We can’t use those de nitions
again. While practicing and learning Python, it may not seem as much of a problem, but in
certain cases, for example, while working on a Read More (https://intellipaat.com/blog/tutorial/py
thon-tutorial/python-modules/)
Python Dates
Python JSON
JSON in Python
JSON is an acronym for JavaScript Object Notation. Python has a built-in package named
‘json’ to support . JSON is basically used for encoding and decoding data. The process of
encoding the JSON data is referred to as serialization as it involves converting data into a
series of bytes that can be stored and transmitted Read More (https://intellipaat.com/blog/tutori
al/python-tutorial/python-json/)
Python RegEx
https://intellipaat.com/blog/tutorial/python-tutorial/ 30/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
PIP Python
Enumerate Python
Queue in Python
https://intellipaat.com/blog/tutorial/python-tutorial/ 31/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Python queue is an important concept in data structure. Queue in Python is nothing but
data item containers. With the help of queue in Python, we can control the ow of our
tasks. Say, we are manipulating data that are collected from a website and then writing the
manipulated data into a .txt le. Now, if Read More (https://intellipaat.com/blog/tutorial/python-tu
torial/python-queue/)
SciPy Tutorial
https://intellipaat.com/blog/tutorial/python-tutorial/ 32/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Introduction:
Data Structure is a collection of data types and set of rules with a format of organizing,
managing and storage which can be used for e cient accessing and modi cation. Data
structures are used in every eld for storing and organizing data in the computer. You can
also download the printable PDF of this Data Structure cheat sheet This Python Read More (h
ttps://intellipaat.com/blog/tutorial/python-tutorial/data-structures-with-python-cheat-sheet/)
https://intellipaat.com/blog/tutorial/python-tutorial/ 33/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
sure that our learners get the best out of our Read More (https://intellipaat.com/blog/tutorial/pyt
hon-tutorial/scikit-learn-cheat-sheet/)
Next (https://intellipaat.com/blog/tutorial/python-tutorial/fundamentals-of-python/)
Recommended Videos
https://intellipaat.com/blog/tutorial/python-tutorial/ 34/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
michele Reply
says:
Reply
Leave a Reply
Your email address will not be published. Required elds are marked *
Comment
https://intellipaat.com/blog/tutorial/python-tutorial/ 35/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Name *
Email *
Post Comment
https://intellipaat.com/blog/tutorial/python-tutorial/ 36/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
Browse Categories
Salesforce (https://intellipaat.com/all-courses/salesforce/)
Database (https://intellipaat.com/all-courses/database/)
Programming (https://intellipaat.com/all-courses/programming/)
Testing (https://intellipaat.com/all-courses/testing/)
https://intellipaat.com/blog/tutorial/python-tutorial/ 37/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
SAP (https://intellipaat.com/all-courses/sap/)
Courses
Courses
Tutorials
Interview Questions
https://intellipaat.com/blog/tutorial/python-tutorial/ 38/39
9/26/2019 Python Tutorial for beginners – Learn Python Programming language basics - Intellipaat
100% SECURE PAYMENTS. ALL MAJOR CREDIT & DEBIT CARDS ACCEPTED OR PAY BY PAYPAL
https://intellipaat.com/blog/tutorial/python-tutorial/ 39/39