SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Getting Started With
Python
SECTION 1
Introduction to Python
2
What is Python?
 Python is a general purpose, high level and powerful dynamic programming
language.
 Python is an Object Oriented Programming language i.e it is based on classes and
objects where each object can communicate with other by exchanging messages and
processing data.
 It's design philosophy is based on the importance of readability and simplicity
− clean and easy to learn syntax
 It is Free and Open Source which means that it is free for download and the source
code is freely available and open for modification and reuse.
 It compiles and runs on a wide variety of UNIX , Windows, MacOS, and various
other platforms.
Why Python is Used for Data Science?
 Python and R are among the most popular programming languages for Data Science
and are often found opposite to each other in the room of debate on the fact that
which one is more valuable. However, both the languages have their specialised
features which makes them unique.
But what is making Python very popular
 One of the main reasons is its syntax simplicity and operability on different
environments making it easy for programmers to write maintainable, large scale
robust code while in R, programming environment is so complex that it requires a
special training.
 Libraries: Python provides data scientists with a set of powerful and efficient libraries
like Scikit, Numpy, Pandas, Scipy that assist data analysis and statistical computing.
Companies Using Python
 Mozilla uses the language for web services. The addon.mozilla.org and
support.mozilla.com websites and the Socorro crash-reporting system are based on
Django and Python. The Firefox Sync Server was also written in Python.
 YouTube is a big user of Python, the entire site uses Python for different
purposes: view video, control templates for website, administer video, access to
canonical data, and many more. Python is everywhere at YouTube.
 Google uses Python as one of the key languages. Python has powered much of
Google’s internal infrastructure.
 Dropbox is completely written in Python language which now has close to 150
million registered users.
 Other companies like Walt Disney, Sony Dreamwork and many more rely heavily
on Python.
Python’s Community & Environment
 Python has an enthusiastic user base, dedicated to encouraging use of the
language, and committed to being diverse and friendly.
 The Python Software Foundation (PSF) is a non profit corporation which promotes,
protects, and advances the Python programming language and supports and
facilitates the growth of a diverse and international community of Python
programmers.
 The PSF manages the open source licensing of Python2.1 and later and own and
protect the trademarks associated with Python.
 Python has a rich and powerful external library support comprises of external
modules and packages. It has a small set of extremely useful built-in functions.
 Automatic memory management system which uses a mix of reference counting and
a cycle detecting garbage collector.
 Python commands are case sensitive.
Source: python.org
IDE
 Integrated Development Environment(IDE) is a software which provides programmers
with an interface combined with all the tools at hand
 Selection of the right IDE influences the productivity and effectiveness of Python
programming
 There are many IDE’s for Python (for data science) such as Spyder
(Scientific PYthon Development EnviRonment) and Rodeo.
 Most recommended and widely used among these is Spyder.
 Spyder includes a Console, Editor, History log, help, variable Explorer, File
Explorer and Projects
SECTION 2
Installing Python
8
Installing Python on Windows, Mac and
Linux OS
 Python is a high level, interpreted language that usually comes pre-installed on all
computers.
 Because Python is widely used for various purposes, it has a lot of packages available
which are all compatible with different versions of the language. This can be painful
for a beginner to manage, right at the introduction to his or her journey.
 The easiest way of installing Python for data science is to use the Data Science
Package Manager, Anaconda. It is the simplest way to install Python with all the
libraries you need, it manages all package compatibility issues and doesn't interfere
with the required system libraries.
 If you still wish to download python separately, you can go to http://www.python.org
and select the version that is suitable for your Operating system and hardware. Be
careful to select the latest stable version.
Anaconda & the Conda Distribution
 The Conda distribution is an open data science platform powered by Python. It
consists of two package managers – Anaconda & Miniconda.
 Anaconda package list includes:
− easy installation of Python(2.7.12, 3.4.5, 3.5.2 and 3.6)
− updates of over 100 pre-built and tested scientific and analytic Python packages
− over 620 more packages available via a simple command:
“conda install <packagename>”.
− open source development environments such as Jupyter/IPython and Spyder and
is supported by Sublime Text 2 and PyCharm.
 However, Anaconda takes up a lot of disk space which is why Miniconda comes in as
an alternative – it includes only conda and Python, where all the other packages can
be installed separately as per your needs.
Installing Anaconda (Simulation)
Steps (for all OS):
 Go to www.continuum.io/downloads to download the installer. Click on the installer link
according to your system. It will take a while to download the .exe file.
 Once you have downloaded the file, open it and follow the instructions of the installer.
Using Spyder as an IDE
 Spyder is an interactive development environment for Python, including an
editor and comes pre-installed with Anaconda.
 The name ‘Spyder’ is derived form “Scientific Python Development
EnviRonment”
 One of it's best features is it's integration with Ipython – a command shell for
interactive programming that is popular amongst Data-Scientists and Software
Engineers alike as it improves productivity as it promotes an execute-explore
workflow instead of an edit-compile-run workflow. Making it great for data
exploration.
 R and MatLab users will be very comfortable using Spyder as it's layout is very
similar the GUI available in these languages.
Spyder – User Interface (Simulation)
After Anaconda is installed, find ‘Spyder’ in your programs menu. It loads all the python
libraries, so it may take a while to start up.
Editor provides features like syntax highlighting, introspection for code
completion, horizontal/vertical splitting features, multiple tabs
facility,etc. You can type commands and see output in the console.
File explorer is a file/directory browser.
Variable explorer shows all global object
references of the current console.
The console is where you can type commands and see output. Spyder
supports multiple Python consoles.
SECTION 3
Writing Your First Python Program
14
Opening Spyder
In our last session we had installed Spyder and seen its features. Now we will program.
Open Spyder
First go to Start menu, find Spyder, open it. We will see an environment like this
Alternatively, you can open Spyder by typing spyder in your command shell.
Working with Directories
Python has the ‘os’ module which provides us with
several useful functions to work with files and
directories.
To get started, import os in your
namespace
Python provides libraries containing methods that allow your programs to interact
with files in your computer. Files and Directories form a Hierarchical structure in your
system drive.
Files contain information. For example: csv files, word files, or python files.
Directories contain files and sub directories inside them. Directories can be helpful in
managing large number of files in your program.
import os
os.getcwd()
'C:UsersHP.spyder'
Working with Directories
os.chdir("C:/Users/HP/Documents/")
• getcwd() returns your current working directory in the form of a string.
• chdir() lets you change the working directory. The new path must be given as
a string to this function.
Both forward (/) or backward
slash() can be used.
# Check the current working directory
# Change the working directory
Create and Save Your File
• By default it opens a temp.py file. We can also open a new file, write commands,
execute them.
• Save the file at a desired folder. It helps to save the script for a later use.
To open a new file, File menu New file.
To save this file , File menu Save as….
‘New file’ option opens up an Untitled file
Writing a Program
Creation of object (an object can store values and further can be used multiple tasks):
• The ‘=‘ operator is used to assign the values to an object.
• Execute or run the command using the enter key in python console and F9
key in Editor. You can run a single command, bunch of commands by
highlighting those, or the entire file at once.
• Comments are used to describe the code and can be added by preceding all
comments with the # symbol.
x=20
x
20
# Create an object x and assign a value 20
Writing a Program
Create another object and perform some mathematical calculations using both the
objects
• ‘+’, and ‘-’ are Arithmetic operators.
y=15
y
15
x+y
35
x*y
300
# Create an object x and assign a value 20
# Add x and y
# Multiply x with y
Writing a Program
• print is a python command to print a text message which must be enclosed in
quotes.
Print numbers:
How to print a message?
print (55)
55
print (4*5)
20
print ("Welcome to Ask Analytics“)
Welcome to Ask Analytics
Help in Python
 Python has an interactive built-in help system consisting of a documentation for
modules, objects or methods.
 To access help in Python, help() function is used.
1. Write help() with no argument in brackets and execute it, the interactive help
system starts on the console. Type the name of module, function, class, method, or
keyword in the console and get the built in documentation printed on the console. To
exit, type “quit”.
2. Another way of getting information is by writing:
help(x) in Editor, execute it and the documentation is displayed on the console. 'x'
can be any kind of object, module, function, package or keyword.
SECTION 4
Introduction to Libraries
23
What are Libraries?
 When used in Python, a library is used loosely to describe a collection of the core modules.
A module is a .py file that contains certain functions and classes that can be used when
called.
 The term ‘standard library‘ in Python language refers to the collection of exact syntax, token
and semantics of the Python language which comes bundled with the core Python
distribution. There are more than 200 modules that form a part of core Python. This library
is written in the C language.
 “Additional libraries” are those libraries that can be added additionally to help with specific
uses in Python. As an open source language, Python has a lot of additonal libraries available.
 Useful Libraries: Numpy, Pandas, SciPy, Matplotlib, Scikit learn and statsmodels
Anaconda & the Conda Distribution
 You need to import a library into an environment before you can call it's functions in
your program.
 To import any library just use any of the following codes -
import math as m
from math import *
SECTION 5
Data Types in Python
26
Objects and Zero Based Indexing
• An object is a memory location which is used to store some data(value).
• Objects are given unique names in order to differentiate between memory locations.
• Every object has a data type based on the value assigned to it. You don’t need to
explicilty declare datatype of the object, Python determines it and keeps track of that
internally.
• Each element of a sequence in an object is assigned a number -its position or index,
where first index is zero, second index is one and so on and so forth. This is known
as Zero Based Indexing.
Python has 5 standard data types which we are going to discuss in this
session
Python Data Types
Note : Use type() function to know the data type of the object.
Numeric values:
• integers (positive or negative whole numbers)- 2, 44, 4645, -245
• floating point numbers- 5.0, 22.2, 1.4556, -55555.675
Numbers
Sequence of characters represented in either pairs of single or
double quotes.
Strings
Sequence of elements which do not need to be of same data type.
Elements and size can be updated.
Lists
Sequence data type similar to the list. Unlike lists, tuples are
enclosed within parentheses ( ( ) ) and cannot be updated.
Tuples
Unordered collection of key-value pairs. Dictionaries are defined
within curly braces ( { } ). Each KEY must be unique, but the VALUE
may be the same for two or more keys.
Dictionary
SECTION 6
String Functions in Python
29
Introduction to Strings
String
• String is a Sequence of characters enclosed in quotation marks.
• Python treats single quotes same as double quotes, although single quotes
are more commonly used.
• A double quoted string literal can contain single quotes and vice versa .
• To add multiple lines in a string, use ‘n’ escape character.
• A triple quoted string literal can span multiple lines without using escape
character.
Built-in Functions
Built-in Functions: There are several functions in Python that allow us to manipulate
strings. Most commonly used functions are:
• lower() converts all the characters to lowercase.
s.lower()
'welcome to the world of python'
• upper() converts all the characters to uppercase.
s.upper()
'welcome to the world of python'
• count() counts how many times a character or sequence of characters occurs in a
string object..
s.count("o")
5
s.count("Python")
1
Built-in Functions
• find() Searches for the given character or sequence of characters within the string
object and returns the first index where it begins or -1 if not found. .
s.find("the")
11
• replace(old, new) replaces all the occurences of old(character or sequence of
characters) with new and returns the copy of the string with replacement.
s.replace("Python", "PYTHON")
'Welcome to the World of PYTHON'
Built-in Functions
• join() is called on a string with argument as a list value and returns a single string
value which is a concatenation of each string in the argument list.
",".join(["orange", "blue", "green"])
'orange,blue,green'
• split() is called on a string value and returns a list of strings
"split does the opposite of join".split()
['split', 'does', 'the', 'opposite', 'of', 'join']
Notice that join() is called on “,” (can be customised) which is inserted
between each string of the list..
By default, it splits wherever the whitespace characters are found. You can
specify a the delimiter string to the split() function to split upon.
SECTION 7
Conditional Statements in Python
34
Conditional Statements
Conditional Statements are useful in decision making when we want to execute a code
only if a certain condition is satisfied.
Condition is referred as a Boolean expression, when evaluated returns either True or False
and depending on that the indented statements get executed.
The most simplest form is if statement. else and elif statements can also be used
depending on the number of conditions to be checked.
Important things to note before using conditional statements in
Python:
• Boolean expression should end with colon ( : )
• The statements that follow must be indented and are called a block
• Statements inside a block must have same indentation.
• The first unindented statement marks the end of the block.
if Statement
n=99
if n<100:
print 'n is less than 100'
n is less than 100
if sum>0:
print 'n is a positive number'
n is a positive number
if..else Statement
x=40
if x>50:
print 'x is greater than 50
else:
print 'x is less than 50'
x is less than 50
This condition evaluates to
false so it will skip the body of
if and the body of else will be
executed.
if..else statements are used when you want to execute one block of code when a
condition is true, and another block of code when it is false.
if..elif..else Statement
x=-11
if x>0:
print 'x is a positive number'
elif x==0:
print 'x is zero'
else:
print 'x is a negative number'
x is a negative number
The if condition and elif
condition evaluates to False so
it executes the statements in
body of else.
if..elif..else statements are used when there are several conditions. Any number
of conditions can be added to elif statement after an if statement and before an
else statement.
elif is short for "else if“. It allows us to check multiple expressions. Similar to
else, elif statement is optional.
SECTION 8
Loops in Python
39
for Loop
Syntax:
for Loop_Variable in Sequence
Statement 1
Statement 2
....
Loop_Variable
Sequence
Statement 1,
Statement 2…
sets a new value for each iteration of the loop.
is a sequence of values assigned to a Loop_Variable
Body of for consisting of block of program
statements
Loops are used when a block of codes needs to be executed multiple times (called
iteration)
for Loop
count=[1,2,3,4]
sum=0
for x in count:
sum=x+sum
print 'sum is', sum
sum is 1
sum is 3
sum is 6
sum is 10
• The number of times the loop should be executed is typically defined in the
initialisation and the condition is evaluated at the end of the loop body.
• Loop variable ‘x’ is created when the for statement runs.
• Initialization statement is terminated by colon(:).
• Loop variable is assigned the next element in the sequence with each iteration
and then the statements of the body are executed.
# List of numbers
THANK YOU!
42

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonAgung Wahyudi
 
POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE teachersduniya.com
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python ProgrammingKamal Acharya
 
Introduction to python programming, Why Python?, Applications of Python
Introduction to python programming, Why Python?, Applications of PythonIntroduction to python programming, Why Python?, Applications of Python
Introduction to python programming, Why Python?, Applications of PythonPro Guide
 
Python PPT
Python PPTPython PPT
Python PPTEdureka!
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An IntroductionSwarit Wadhe
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Edureka!
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming KrishnaMildain
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming pptismailmrribi
 
11 Unit 1 Chapter 03 Data Handling
11   Unit 1 Chapter 03 Data Handling11   Unit 1 Chapter 03 Data Handling
11 Unit 1 Chapter 03 Data HandlingPraveen M Jigajinni
 
Python final presentation kirti ppt1
Python final presentation kirti ppt1Python final presentation kirti ppt1
Python final presentation kirti ppt1Kirti Verma
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on pythonwilliam john
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for KidsAimee Maree Forsstrom
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaEdureka!
 

Was ist angesagt? (20)

Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 
Introduction to python programming, Why Python?, Applications of Python
Introduction to python programming, Why Python?, Applications of PythonIntroduction to python programming, Why Python?, Applications of Python
Introduction to python programming, Why Python?, Applications of Python
 
Introduction to Python Basics Programming
Introduction to Python Basics ProgrammingIntroduction to Python Basics Programming
Introduction to Python Basics Programming
 
Python PPT
Python PPTPython PPT
Python PPT
 
Python basics
Python basicsPython basics
Python basics
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
 
11 Unit 1 Chapter 03 Data Handling
11   Unit 1 Chapter 03 Data Handling11   Unit 1 Chapter 03 Data Handling
11 Unit 1 Chapter 03 Data Handling
 
Python final presentation kirti ppt1
Python final presentation kirti ppt1Python final presentation kirti ppt1
Python final presentation kirti ppt1
 
Basics of python
Basics of pythonBasics of python
Basics of python
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on python
 
Introduction python
Introduction pythonIntroduction python
Introduction python
 
Introduction to python
 Introduction to python Introduction to python
Introduction to python
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for Kids
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | Edureka
 

Ähnlich wie Getting Started with Python

Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialQA TrainingHub
 
python programming.pptx
python programming.pptxpython programming.pptx
python programming.pptxKaviya452563
 
Introduction to Python.pptx
Introduction to Python.pptxIntroduction to Python.pptx
Introduction to Python.pptxSamyakJain461
 
Why Python Should Be Your First Programming Language
Why Python Should Be Your First Programming LanguageWhy Python Should Be Your First Programming Language
Why Python Should Be Your First Programming LanguageEdureka!
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1Kanchilug
 
Introduction of python programming
Introduction of python programmingIntroduction of python programming
Introduction of python programmingNitin Kumar Kashyap
 
Basic Python Introduction Lecture 1.pptx
Basic Python Introduction Lecture 1.pptxBasic Python Introduction Lecture 1.pptx
Basic Python Introduction Lecture 1.pptxAditya Patel
 
session5-Getting stated with Python.pdf
session5-Getting stated with Python.pdfsession5-Getting stated with Python.pdf
session5-Getting stated with Python.pdfAyushDutta32
 
Training report 1923-b.e-eee-batchno--intern-54 (1).pdf
Training report 1923-b.e-eee-batchno--intern-54 (1).pdfTraining report 1923-b.e-eee-batchno--intern-54 (1).pdf
Training report 1923-b.e-eee-batchno--intern-54 (1).pdfYadavHarshKr
 
Ways To Become A Good Python Developer
Ways To Become A Good Python DeveloperWays To Become A Good Python Developer
Ways To Become A Good Python DeveloperCodeMonk
 

Ähnlich wie Getting Started with Python (20)

Cmpe202 01 Research
Cmpe202 01 ResearchCmpe202 01 Research
Cmpe202 01 Research
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
Python basic
Python basicPython basic
Python basic
 
Python
Python Python
Python
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Python for Beginners.docx
Python for Beginners.docxPython for Beginners.docx
Python for Beginners.docx
 
Research paper on python by Rj
Research paper on python by RjResearch paper on python by Rj
Research paper on python by Rj
 
python programming.pptx
python programming.pptxpython programming.pptx
python programming.pptx
 
Introduction to Python.pptx
Introduction to Python.pptxIntroduction to Python.pptx
Introduction to Python.pptx
 
Why Python Should Be Your First Programming Language
Why Python Should Be Your First Programming LanguageWhy Python Should Be Your First Programming Language
Why Python Should Be Your First Programming Language
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
Introduction of python programming
Introduction of python programmingIntroduction of python programming
Introduction of python programming
 
Basic Python Introduction Lecture 1.pptx
Basic Python Introduction Lecture 1.pptxBasic Python Introduction Lecture 1.pptx
Basic Python Introduction Lecture 1.pptx
 
Python
PythonPython
Python
 
Python Class 1
Python Class 1Python Class 1
Python Class 1
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
session5-Getting stated with Python.pdf
session5-Getting stated with Python.pdfsession5-Getting stated with Python.pdf
session5-Getting stated with Python.pdf
 
Training report 1923-b.e-eee-batchno--intern-54 (1).pdf
Training report 1923-b.e-eee-batchno--intern-54 (1).pdfTraining report 1923-b.e-eee-batchno--intern-54 (1).pdf
Training report 1923-b.e-eee-batchno--intern-54 (1).pdf
 
Ways To Become A Good Python Developer
Ways To Become A Good Python DeveloperWays To Become A Good Python Developer
Ways To Become A Good Python Developer
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Mehr von Sankhya_Analytics

Mehr von Sankhya_Analytics (9)

Data Management in Python
Data Management in PythonData Management in Python
Data Management in Python
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL II
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 
Getting Started with R
Getting Started with RGetting Started with R
Getting Started with R
 
Data Management in R
Data Management in RData Management in R
Data Management in R
 
Basic Analysis using R
Basic Analysis using RBasic Analysis using R
Basic Analysis using R
 
R Get Started II
R Get Started IIR Get Started II
R Get Started II
 
R Get Started I
R Get Started IR Get Started I
R Get Started I
 

Kürzlich hochgeladen

Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...gajnagarg
 
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...gajnagarg
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...amitlee9823
 
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...amitlee9823
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...karishmasinghjnh
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Pooja Nehwal
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...amitlee9823
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...gajnagarg
 

Kürzlich hochgeladen (20)

Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls kakinada Escorts ☎️9352988975 Two shot with one girl...
 
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men  🔝Sambalpur🔝   Esc...
➥🔝 7737669865 🔝▻ Sambalpur Call-girls in Women Seeking Men 🔝Sambalpur🔝 Esc...
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...
 

Getting Started with Python

  • 3. What is Python?  Python is a general purpose, high level and powerful dynamic programming language.  Python is an Object Oriented Programming language i.e it is based on classes and objects where each object can communicate with other by exchanging messages and processing data.  It's design philosophy is based on the importance of readability and simplicity − clean and easy to learn syntax  It is Free and Open Source which means that it is free for download and the source code is freely available and open for modification and reuse.  It compiles and runs on a wide variety of UNIX , Windows, MacOS, and various other platforms.
  • 4. Why Python is Used for Data Science?  Python and R are among the most popular programming languages for Data Science and are often found opposite to each other in the room of debate on the fact that which one is more valuable. However, both the languages have their specialised features which makes them unique. But what is making Python very popular  One of the main reasons is its syntax simplicity and operability on different environments making it easy for programmers to write maintainable, large scale robust code while in R, programming environment is so complex that it requires a special training.  Libraries: Python provides data scientists with a set of powerful and efficient libraries like Scikit, Numpy, Pandas, Scipy that assist data analysis and statistical computing.
  • 5. Companies Using Python  Mozilla uses the language for web services. The addon.mozilla.org and support.mozilla.com websites and the Socorro crash-reporting system are based on Django and Python. The Firefox Sync Server was also written in Python.  YouTube is a big user of Python, the entire site uses Python for different purposes: view video, control templates for website, administer video, access to canonical data, and many more. Python is everywhere at YouTube.  Google uses Python as one of the key languages. Python has powered much of Google’s internal infrastructure.  Dropbox is completely written in Python language which now has close to 150 million registered users.  Other companies like Walt Disney, Sony Dreamwork and many more rely heavily on Python.
  • 6. Python’s Community & Environment  Python has an enthusiastic user base, dedicated to encouraging use of the language, and committed to being diverse and friendly.  The Python Software Foundation (PSF) is a non profit corporation which promotes, protects, and advances the Python programming language and supports and facilitates the growth of a diverse and international community of Python programmers.  The PSF manages the open source licensing of Python2.1 and later and own and protect the trademarks associated with Python.  Python has a rich and powerful external library support comprises of external modules and packages. It has a small set of extremely useful built-in functions.  Automatic memory management system which uses a mix of reference counting and a cycle detecting garbage collector.  Python commands are case sensitive. Source: python.org
  • 7. IDE  Integrated Development Environment(IDE) is a software which provides programmers with an interface combined with all the tools at hand  Selection of the right IDE influences the productivity and effectiveness of Python programming  There are many IDE’s for Python (for data science) such as Spyder (Scientific PYthon Development EnviRonment) and Rodeo.  Most recommended and widely used among these is Spyder.  Spyder includes a Console, Editor, History log, help, variable Explorer, File Explorer and Projects
  • 9. Installing Python on Windows, Mac and Linux OS  Python is a high level, interpreted language that usually comes pre-installed on all computers.  Because Python is widely used for various purposes, it has a lot of packages available which are all compatible with different versions of the language. This can be painful for a beginner to manage, right at the introduction to his or her journey.  The easiest way of installing Python for data science is to use the Data Science Package Manager, Anaconda. It is the simplest way to install Python with all the libraries you need, it manages all package compatibility issues and doesn't interfere with the required system libraries.  If you still wish to download python separately, you can go to http://www.python.org and select the version that is suitable for your Operating system and hardware. Be careful to select the latest stable version.
  • 10. Anaconda & the Conda Distribution  The Conda distribution is an open data science platform powered by Python. It consists of two package managers – Anaconda & Miniconda.  Anaconda package list includes: − easy installation of Python(2.7.12, 3.4.5, 3.5.2 and 3.6) − updates of over 100 pre-built and tested scientific and analytic Python packages − over 620 more packages available via a simple command: “conda install <packagename>”. − open source development environments such as Jupyter/IPython and Spyder and is supported by Sublime Text 2 and PyCharm.  However, Anaconda takes up a lot of disk space which is why Miniconda comes in as an alternative – it includes only conda and Python, where all the other packages can be installed separately as per your needs.
  • 11. Installing Anaconda (Simulation) Steps (for all OS):  Go to www.continuum.io/downloads to download the installer. Click on the installer link according to your system. It will take a while to download the .exe file.  Once you have downloaded the file, open it and follow the instructions of the installer.
  • 12. Using Spyder as an IDE  Spyder is an interactive development environment for Python, including an editor and comes pre-installed with Anaconda.  The name ‘Spyder’ is derived form “Scientific Python Development EnviRonment”  One of it's best features is it's integration with Ipython – a command shell for interactive programming that is popular amongst Data-Scientists and Software Engineers alike as it improves productivity as it promotes an execute-explore workflow instead of an edit-compile-run workflow. Making it great for data exploration.  R and MatLab users will be very comfortable using Spyder as it's layout is very similar the GUI available in these languages.
  • 13. Spyder – User Interface (Simulation) After Anaconda is installed, find ‘Spyder’ in your programs menu. It loads all the python libraries, so it may take a while to start up. Editor provides features like syntax highlighting, introspection for code completion, horizontal/vertical splitting features, multiple tabs facility,etc. You can type commands and see output in the console. File explorer is a file/directory browser. Variable explorer shows all global object references of the current console. The console is where you can type commands and see output. Spyder supports multiple Python consoles.
  • 14. SECTION 3 Writing Your First Python Program 14
  • 15. Opening Spyder In our last session we had installed Spyder and seen its features. Now we will program. Open Spyder First go to Start menu, find Spyder, open it. We will see an environment like this Alternatively, you can open Spyder by typing spyder in your command shell.
  • 16. Working with Directories Python has the ‘os’ module which provides us with several useful functions to work with files and directories. To get started, import os in your namespace Python provides libraries containing methods that allow your programs to interact with files in your computer. Files and Directories form a Hierarchical structure in your system drive. Files contain information. For example: csv files, word files, or python files. Directories contain files and sub directories inside them. Directories can be helpful in managing large number of files in your program.
  • 17. import os os.getcwd() 'C:UsersHP.spyder' Working with Directories os.chdir("C:/Users/HP/Documents/") • getcwd() returns your current working directory in the form of a string. • chdir() lets you change the working directory. The new path must be given as a string to this function. Both forward (/) or backward slash() can be used. # Check the current working directory # Change the working directory
  • 18. Create and Save Your File • By default it opens a temp.py file. We can also open a new file, write commands, execute them. • Save the file at a desired folder. It helps to save the script for a later use. To open a new file, File menu New file. To save this file , File menu Save as…. ‘New file’ option opens up an Untitled file
  • 19. Writing a Program Creation of object (an object can store values and further can be used multiple tasks): • The ‘=‘ operator is used to assign the values to an object. • Execute or run the command using the enter key in python console and F9 key in Editor. You can run a single command, bunch of commands by highlighting those, or the entire file at once. • Comments are used to describe the code and can be added by preceding all comments with the # symbol. x=20 x 20 # Create an object x and assign a value 20
  • 20. Writing a Program Create another object and perform some mathematical calculations using both the objects • ‘+’, and ‘-’ are Arithmetic operators. y=15 y 15 x+y 35 x*y 300 # Create an object x and assign a value 20 # Add x and y # Multiply x with y
  • 21. Writing a Program • print is a python command to print a text message which must be enclosed in quotes. Print numbers: How to print a message? print (55) 55 print (4*5) 20 print ("Welcome to Ask Analytics“) Welcome to Ask Analytics
  • 22. Help in Python  Python has an interactive built-in help system consisting of a documentation for modules, objects or methods.  To access help in Python, help() function is used. 1. Write help() with no argument in brackets and execute it, the interactive help system starts on the console. Type the name of module, function, class, method, or keyword in the console and get the built in documentation printed on the console. To exit, type “quit”. 2. Another way of getting information is by writing: help(x) in Editor, execute it and the documentation is displayed on the console. 'x' can be any kind of object, module, function, package or keyword.
  • 24. What are Libraries?  When used in Python, a library is used loosely to describe a collection of the core modules. A module is a .py file that contains certain functions and classes that can be used when called.  The term ‘standard library‘ in Python language refers to the collection of exact syntax, token and semantics of the Python language which comes bundled with the core Python distribution. There are more than 200 modules that form a part of core Python. This library is written in the C language.  “Additional libraries” are those libraries that can be added additionally to help with specific uses in Python. As an open source language, Python has a lot of additonal libraries available.  Useful Libraries: Numpy, Pandas, SciPy, Matplotlib, Scikit learn and statsmodels
  • 25. Anaconda & the Conda Distribution  You need to import a library into an environment before you can call it's functions in your program.  To import any library just use any of the following codes - import math as m from math import *
  • 26. SECTION 5 Data Types in Python 26
  • 27. Objects and Zero Based Indexing • An object is a memory location which is used to store some data(value). • Objects are given unique names in order to differentiate between memory locations. • Every object has a data type based on the value assigned to it. You don’t need to explicilty declare datatype of the object, Python determines it and keeps track of that internally. • Each element of a sequence in an object is assigned a number -its position or index, where first index is zero, second index is one and so on and so forth. This is known as Zero Based Indexing. Python has 5 standard data types which we are going to discuss in this session
  • 28. Python Data Types Note : Use type() function to know the data type of the object. Numeric values: • integers (positive or negative whole numbers)- 2, 44, 4645, -245 • floating point numbers- 5.0, 22.2, 1.4556, -55555.675 Numbers Sequence of characters represented in either pairs of single or double quotes. Strings Sequence of elements which do not need to be of same data type. Elements and size can be updated. Lists Sequence data type similar to the list. Unlike lists, tuples are enclosed within parentheses ( ( ) ) and cannot be updated. Tuples Unordered collection of key-value pairs. Dictionaries are defined within curly braces ( { } ). Each KEY must be unique, but the VALUE may be the same for two or more keys. Dictionary
  • 30. Introduction to Strings String • String is a Sequence of characters enclosed in quotation marks. • Python treats single quotes same as double quotes, although single quotes are more commonly used. • A double quoted string literal can contain single quotes and vice versa . • To add multiple lines in a string, use ‘n’ escape character. • A triple quoted string literal can span multiple lines without using escape character.
  • 31. Built-in Functions Built-in Functions: There are several functions in Python that allow us to manipulate strings. Most commonly used functions are: • lower() converts all the characters to lowercase. s.lower() 'welcome to the world of python' • upper() converts all the characters to uppercase. s.upper() 'welcome to the world of python' • count() counts how many times a character or sequence of characters occurs in a string object.. s.count("o") 5 s.count("Python") 1
  • 32. Built-in Functions • find() Searches for the given character or sequence of characters within the string object and returns the first index where it begins or -1 if not found. . s.find("the") 11 • replace(old, new) replaces all the occurences of old(character or sequence of characters) with new and returns the copy of the string with replacement. s.replace("Python", "PYTHON") 'Welcome to the World of PYTHON'
  • 33. Built-in Functions • join() is called on a string with argument as a list value and returns a single string value which is a concatenation of each string in the argument list. ",".join(["orange", "blue", "green"]) 'orange,blue,green' • split() is called on a string value and returns a list of strings "split does the opposite of join".split() ['split', 'does', 'the', 'opposite', 'of', 'join'] Notice that join() is called on “,” (can be customised) which is inserted between each string of the list.. By default, it splits wherever the whitespace characters are found. You can specify a the delimiter string to the split() function to split upon.
  • 35. Conditional Statements Conditional Statements are useful in decision making when we want to execute a code only if a certain condition is satisfied. Condition is referred as a Boolean expression, when evaluated returns either True or False and depending on that the indented statements get executed. The most simplest form is if statement. else and elif statements can also be used depending on the number of conditions to be checked. Important things to note before using conditional statements in Python: • Boolean expression should end with colon ( : ) • The statements that follow must be indented and are called a block • Statements inside a block must have same indentation. • The first unindented statement marks the end of the block.
  • 36. if Statement n=99 if n<100: print 'n is less than 100' n is less than 100 if sum>0: print 'n is a positive number' n is a positive number
  • 37. if..else Statement x=40 if x>50: print 'x is greater than 50 else: print 'x is less than 50' x is less than 50 This condition evaluates to false so it will skip the body of if and the body of else will be executed. if..else statements are used when you want to execute one block of code when a condition is true, and another block of code when it is false.
  • 38. if..elif..else Statement x=-11 if x>0: print 'x is a positive number' elif x==0: print 'x is zero' else: print 'x is a negative number' x is a negative number The if condition and elif condition evaluates to False so it executes the statements in body of else. if..elif..else statements are used when there are several conditions. Any number of conditions can be added to elif statement after an if statement and before an else statement. elif is short for "else if“. It allows us to check multiple expressions. Similar to else, elif statement is optional.
  • 39. SECTION 8 Loops in Python 39
  • 40. for Loop Syntax: for Loop_Variable in Sequence Statement 1 Statement 2 .... Loop_Variable Sequence Statement 1, Statement 2… sets a new value for each iteration of the loop. is a sequence of values assigned to a Loop_Variable Body of for consisting of block of program statements Loops are used when a block of codes needs to be executed multiple times (called iteration)
  • 41. for Loop count=[1,2,3,4] sum=0 for x in count: sum=x+sum print 'sum is', sum sum is 1 sum is 3 sum is 6 sum is 10 • The number of times the loop should be executed is typically defined in the initialisation and the condition is evaluated at the end of the loop body. • Loop variable ‘x’ is created when the for statement runs. • Initialization statement is terminated by colon(:). • Loop variable is assigned the next element in the sequence with each iteration and then the statements of the body are executed. # List of numbers

Hinweis der Redaktion

  1. 3
  2. 4
  3. 5
  4. 6
  5. 7
  6. 9
  7. 10
  8. 11
  9. 12
  10. 13
  11. 15
  12. 18
  13. 19
  14. 20
  15. 21
  16. 22
  17. 24
  18. 25
  19. 35
  20. 36
  21. 37
  22. 38