0% found this document useful (0 votes)
22 views15 pages

Introduction To Python

The document provides an introduction to Python, highlighting its general-purpose nature and applications in various fields such as data science and web programming. It covers the Python environment, including the use of Anaconda and Jupyter notebooks, as well as fundamental concepts like variables, data types, operators, user-defined functions, and popular libraries like Numpy. Additionally, it explains how to set the working directory and includes examples of Python syntax and functionality.

Uploaded by

krishna
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views15 pages

Introduction To Python

The document provides an introduction to Python, highlighting its general-purpose nature and applications in various fields such as data science and web programming. It covers the Python environment, including the use of Anaconda and Jupyter notebooks, as well as fundamental concepts like variables, data types, operators, user-defined functions, and popular libraries like Numpy. Additionally, it explains how to set the working directory and includes examples of Python syntax and functionality.

Uploaded by

krishna
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INTRODUCTION TO PYTHON

PYTHON LANGUAGE
• Python is a general purpose language developed by Guido van Rossum.
• Python is used in data science, web programming, game development,
desktop applications and many other scientific applications.
• Python is a scripting language with structured programming style.
• Python has a dynamic built in data structure
• Python has database connectivity interfaces to MySQL, Oracle, PostgreSQL
etc.
• Python is an extensible language that can be easily integrated with other
programming languages such as C, C++ etc.
• Python has libraries for internet protocols like HTML, XML, JSON etc., which
helps for web application development
Python environment
• Anaconda is the most widely used Python distribution for data
science and comes pre-loaded with all the most popular libraries and
tools.
• Anaconda Navigator is a desktop GUI that comes along with
Anaconda Individual Edition.
• The Jupyter notebook application allows you to create and edit
documents that display the input and output of a Python or R
language script.
• Jupyter notebook integrates code and its output into a single
document that combines visualizations, narrative text, mathematical
equations, and other rich media.
Set Working Directory in Python
• Python function chdir() changes the current working directory to the given
path.
• OS library in Python provides functions for interacting with the operating
system.
• The function chdir() is available in OS library.

• import os
• [Link]("D:/datascience/yourfoldername")

• path = [Link]()
• print(path)
Comment Statements in Python
• Like R programming language, comments statements are written with
# symbol at the beginning.
• Comment statements are not executed.

• ### My First Python Program ###


• x=10
• y=50
• z=x+y
• print(z)
Variables in Python
• Variables store values in designated memory locations.
• A variable reserves certain memory space depending on the type of
values assigned, such as integers, decimals or characters.
• When values are assigned to the variables, they are created with a
particular data type based on the assigned values.
• Variable names must start with an alphabet or underscore character
and not with numbers.
• A variable name can contain only contain alpha numeric characters
and underscores.
Data Types in Python
• The data types available in Python are
• Numbers - Number data types store numeric values.
• String - Strings in Python are set of characters represented in the single or
double quotation marks.
• List - A list contains items separated by commas and enclosed within square
brackets [ ].
• Tuple - A tuple consists of a number of values separated by commas.
• Dictionary - Dictionary consist of key-value pairs. A dictionary key is variable
that can be any Python type
Python Strings Python Lists Python Tuple Python Dictionary
first = 'My First firstlist = [21, "John", 23.5, "Apple", firsttuple = ('Henry', 200, 'Jack', 400,
'Catherine', 500) firstdict = {'name':
Program' 4, 10]
'john',2:10000, 'dept':
print(firsttuple) 'sales'}
print(first) print(firstlist)
print(firstdict)
print(first[0])
print(firstlist[0])
print(first[0:8]) print(firsttuple[0])
print(first[8:]) print(firstlist[2:5]) print(firstdict['name'])
print(firsttuple[2:5])
print(first*2) print(firstlist[4:]) print(firsttuple[3:]) print(firstdict[2])
print(first+" in print(firstlist*2) print(firsttuple*2)
print([Link]())
Python") secondlist = [1000, 2000, "Henry"] secondtuple = ("josh", 600)
print(firstlist+secondlist) print(firsttuple+secondtuple) print([Link]())

firstlist[2]="New"
firstlist firsttuple[2]="New"
Operators in Python
Assignment
Description
Operator
Assigns the result of right side of the expression to
= the operand on the left side
Arithmetic Description
Add right side operand with left side operand and Operator
+= assign the result to left operand
+ Addition
Subtract right operand from left operand and assign
-= the result to left operand - Subtraction
Multiply right operand with left operand and assign * Multiplication
*= the result to left operand
/ Division
Divide left operand with right operand and assign the
/= result to left operand % Modulus. Gives remainder after
division
Calculates modulus using left and right operands and
%= assign the result to left operand ** Exponentiation
Divide left operand with right operand and assign the // Floor division. Gives quotient
//= quotient to left operand after division
Calculates exponent value using the operands and
Operators in Python
Relationalship Name
Operator

== Equal

!= Not equal

> Greater than

< Less than

>= Greater than or equal to

<= Less than or equal to

Membership Description Logical Description


Operator Operator

in Returns True if a sequence with the specified value and Returns True if both statements are true
is present in the object
or Returns True if one of the statements is true
not in Returns True if a sequence with the specified value
not Reverse the result, returns False if the result
is not present in the object
is true
User defined functions in Python

• def function_name (parameter list):


• “function docstring”
• function statement 1
• function statement 2
• …
• return expression

• Function docstring
• function_name.__doc__
Lambda function in Python

• lambda argument(s) : expression

• sum = lambda a,b : a+b

• def sum(a,b)
return a+b
Example
• def add(x,y):
• "Adds two values and return the result"
• z=x+y
• return z

• add.__doc__
Python Libraries
• Python library is a collection of syntax and semantics of python
language that can be included in programs.
• Python libraries handle basic functionality like Input/Output
operations, visualization techniques and also complicated database
operations.
• The libraries enhance the portability of the programs and makes it
platform independent.
• Some popular Python libraries are Numpy, Pandas, SciPy, Matplotlib,
Keras etc.
Numpy Library
• Numpy stands for Numerical Python
• Numpy is a popular package used for array-processing.
• It also has functions for performing mathematical applications such as
matrices and algebra.

• import numpy as np

You might also like