i-HUB IIT Roorkee
DST Bihar
GEC Aurangabad
Skill Development Program
Python…… Explore to Data World
Introduction to Python
Python programming language is one of the most popular programming languages in the
world right now. With the ease of access and easier implementations of complex-looking
tasks, the Python programing language has made its mark in the IT industry.
The scalability of the Python programming language is immense and can be implemented
almost in every domain. Data Science has reached another milestone with Python, and the
amount of data flowing in each year, Python came as a savior and helped achieve
revolutionary developments in the Data Science market.
Getting Started With Python
Walk Through
Why to Learn Python?
Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed
to be highly readable. It uses English keywords frequently where as other languages use punctuation,
and it has fewer syntactical constructions than other languages.
Some of the key advantages of learning Python:
• Python is Interpreted − Python is processed at runtime by the interpreter. You do not need to compile your
program before executing it. This is similar to PERL and PHP.
• Python is Interactive − You can actually sit at a Python prompt and interact with the interpreter directly to write
your programs.
• Python is Object-Oriented − Python supports Object-Oriented style or technique of programming that
encapsulates code within objects.
• Python is a Beginner's Language − Python is a great language for the beginner-level programmers and supports
the development of a wide range of applications from simple text processing to WWW browsers to games.
Characteristics of Python
Following are important characteristics of Python Programming −
• It supports functional and structured programming methods as well as OOP.
• It can be used as a scripting language or can be compiled to byte-code for building
large applications.
• It provides very high-level dynamic data types and supports dynamic type checking.
• It supports automatic garbage collection.
• It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
Applications of Python
Python is one of the most widely used language over the web. Listing few of them here:
• Easy-to-learn − Python has few keywords, simple structure, and a clearly defined syntax.
• Easy-to-read − Python code is more clearly defined and visible in natural way.
• Easy-to-maintain − Python's source code is fairly easy-to-maintain.
• A broad standard library − Python's bulk of the library is very portable and cross-platform compatible on UNIX,
Windows, and Macintosh.
• Interactive Mode − Python has support for an interactive mode which allows interactive testing and debugging
of snippets of code.
• Portable − Python can run on a wide variety of hardware platforms and has the same interface on all platforms.
• Extendable − You can add low-level modules to the Python interpreter. These modules enable programmers to
add to or customize their tools to be more efficient.
• Databases − Python provides interfaces to all major commercial databases.
• GUI Programming − Python supports GUI applications that can be created and ported to many system calls,
libraries and windows systems, such as Windows MFC, Macintosh, and the X Window system of Unix.
• Scalable − Python provides a better structure and support for large programs than shell scripting.
Python Basics
After setting up the Python environment, installing suitable IDEs begin learning with the very basics. Even though the basics
are pretty similar to any other programming language, but it’s required to learn Python from basics as well to build strong
debugging and scripting skills.
Advanced Python Concepts
Advanced concepts in Python that will give you a clearer perspective on how things are done with Python
with advanced Python concepts.
Python For Data Science
Data Science with Python. Since, Data Science is the hottest job profile in the current
market scenario, learning Data Science with Python will give boost professional growth as
well.
Python For Machine Learning
Machine Learning is another aspect of learning Python. With sophisticated library
support and features that Python offers.
Jump into Python World !!!!
Basics of
Python
Introduction to Python
Python is a very popular general-purpose interpreted, interactive, object-oriented,
and high-level programming language. Python is dynamically-typed and garbage-
collected programming language. It was created by Guido van Rossum during
1985- 1990. Like Perl, Python source code is also available under the GNU General
Public License (GPL).
Python supports multiple programming paradigms, including Procedural, Object Oriented and Functional
programming language. Python design philosophy emphasizes code readability with the use of significant
indentation.
There are many other good reasons which makes Python as the top choice of any programmer:
• Python is Open Source which means its available free of cost.
• Python is simple and so easy to learn
• Python is versatile and can be used to create many different things.
• Python has powerful development libraries include AI, ML etc.
• Python is much in demand and ensures high salary
Advantage of Python
Some of the key advantages of learning Python:
• Python is Interpreted − Python is processed at runtime by the interpreter. You do not need to compile
your program before executing it. This is similar to PERL and PHP.
• Python is Interactive − You can actually sit at a Python prompt and interact with the interpreter
directly to write your programs.
• Python is Object-Oriented − Python supports Object-Oriented style or technique of programming that
encapsulates code within objects.
• Python is a Beginner's Language − Python is a great language for the beginner-level programmers and
supports the development of a wide range of applications from simple text processing to WWW
browsers to games.
Following are important characteristics of Python Programming −
• It supports functional and structured programming methods as well as OOP.
• It can be used as a scripting language or can be compiled to byte-code for
building large applications.
• It provides very high-level dynamic data types and supports dynamic type
checking.
• It supports automatic garbage collection.
• It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
Python - Basic Syntax
First Python Program
print("Hello Python World")
Python Identifiers
• A Python identifier is a name used to identify a variable, function, class,
module or other object. An identifier starts with a letter A to Z or a to z or an
underscore (_) followed by zero or more letters, underscores and digits (0 to
9).
• Python does not allow punctuation characters such as @, $, and % within
identifiers. Python is a case sensitive programming language. Thus,
Manpower and manpower are two different identifiers in Python.
Variable and Data Structures
In other programming languages like C, C++ and Java, you will need to declare the type of
variables but in Python you don’t need to do that. Just type in the variable and when
values will be given to it, then it will automatically know whether the value given would
be a int, float or char or even a String.
# Python program to declare variables
myNumber = 3
print(myNumber)
myNumber2 = 4.5
print(myNumber2)
myNumber ="helloworld"
print(myNumber)
Data Structure …
• Python have 4 types of built in Data Structures namely List, Dictionary, Tuple and Set.
• List is the most basic Data Structure in python. List is mutable data structure i.e items can be
added to list later after the list creation. Its like you are going to shop at local market and made a
list of some items and later on you can add more and more items to the list.
append() function is used to add data to the list.
# Python program to illustrate list
# creates a empty list
nums = []
# appending data in list
[Link](21)
[Link](40.5)
[Link]("String")
print(nums)
Input and Output
• In this section, we will learn how to take input from the user and hence manipulate it or
simply display it. input() function is used to take input from the user.
# Python program to illustrate
# getting input from user
name = input("Enter your name: ")
# user entered the name ‘Siddhant'
print("hello", name)
# Python3 program to get input from user
# accepting integer from the user
num1 = int(input("Enter num1: "))
num2 = int(input("Enter num2: "))
num3 = num1 * num2
print("Product is: ", num3)
Selection or Conditional Statement
Selection in Python is made using the two keywords ‘if’ and ‘elif’ and else (elseif)
# Python program to illustrate
# selection statement
num1 = 34
if(num1>12):
print("Num1 is good")
elif(num1>35):
print("Num2 is better....")
else:
print("Num2 is great")
Functions
• Functions like a bunch of code that is intended to do a particular task in the
whole Python script. Python used the keyword ‘def’ to define a function.
Syntax:
def function-name(arguments):
#function body
# Python program to illustrate
# functions
def hello():
print("hello")
print("hello again")
hello()
# calling function
hello()
Recursive Function Program
# Python program to illustrate
# function with main
def getInteger():
result = int(input("Enter integer: "))
return result
def Main():
print("Started")
# calling the getInteger function and
# storing its returned value in the output variable
output = getInteger()
print(output)
# now we are required to tell Python
# for 'Main' function existence
if __name__=="__main__":
Main()
Iteration
As the name suggests it calls repeating things again and again. We will
use the most popular ‘for’ loop here.
# Python program to illustrate
# a simple for loop
for step in range(5):
print(step)
Module
• Python has a very rich module library that has several functions to do many tasks.
• ‘import’ keyword is used to import a particular module into your python code. For
instance consider the following program.
# Python program to illustrate
# math module
import math
def Main():
num = float(input("Enter a number: "))
# fabs is used to get the absolute value of a decimal
num = [Link](num)
print(num)
if __name__=="__main__":
Main()