Getting Started with Python
2. LIVE On-line Class
Class Recording in LMS
24/7 Post Class Support
Module Wise Quiz and Assignment
Project Work on Large Data Set
Slide 2 www.edureka.in/python
How it Works?
3. Slide 3Slide 3 www.edureka.in/python
» Getting Started with Python
» Sequences and File Operations
» Deep Dive - Functions, Sorting, Errors and Exception
Handling, Regular Expressions and Packages
» Object Oriented Programming in Python
» Debugging, Databases and Project Skeletons
» Machine Learning Using Python – I
» Machine Learning Using Python – II
» Introduction to Hadoop
» Hadoop and Python
» Web Scraping using Python and Project Work
4. Slide 4 www.edureka.in/python
Understand Python- an Object-oriented Programming Language.
List the users of Python for Data Analytics.
Define Identifiers and indentation.
List Operations on Numbers and Operations on Strings.
Run a Python Script.
At the end of this module, you will be able to:
5. Slide 5 www.edureka.in/python
Python is a very-high-level dynamic object-oriented programming language.
Python is easy to program and read.
Similar to PERL, but with powerful typing and object oriented features.
What is Python?
Commonly used for producing
HTML content on websites
<class ‘A’> <class ‘B’>
Useful built-in types
Great for text
.pyc, .pyd, .pyo
6. Slide 6 www.edureka.in/python
» Python focuses on readability, coherence, and software quality in general which sets it
apart from other languages in the scripting world.
7. Slide 7 www.edureka.in/python
» Python code is typically one-third to one-fifth the size of equivalent C++ or Java code.
That means there is less to type, less to debug, and less to maintain.
8. Slide 8 www.edureka.in/python
» Python programs run unchanged on all major computer platforms. For Example-
Windows, Linux, MAC OS etc.
9. Slide 9 www.edureka.in/python
» Python comes with a large collection of prebuilt and portable functionality, known as the
Standard Library. This library supports an array of application-level programming tasks,
from text pattern matching to network scripting.
10. Slide 10 www.edureka.in/python
» Python scripts can easily communicate with other parts of an application, using a variety
of integration mechanisms.
11. Slide 11 www.edureka.in/python
Enjoyment » Because of Python’s ease of use and built-in toolset, it makes the programming more
12. Slide 12 www.edureka.in/python
Invented in the Netherlands in early 90s by Guido van Rossum.
Named after “Monty Python”, a comedy group, as Python is fun to
Open source and interpreted language.
Considered a scripting language, but is much more than that.
Scalable, object oriented and functional.
Used by Google, increasingly popular.
Python job trends from indeed.com shows remarkable increase
Python is at the top of the list among the top-dogs—Java,
Reference: indeed.com http://www.indeed.com/jobtrends?q=Java%2C+PHP%2C+Perl%2C+.Net%2C+Python&relative=1
13. Slide 13 www.edureka.in/python
Users of Python
» Dropbox web-based file hosting service is
implemented using Python
» Both the Dropbox server (running in the cloud) and
desktop client software are primarily written
» Yahoo acquired Four11, whose address and
mapping lookup services were implemented in
» Yahoo Maps uses Python.
» Many components of the Google spider and search
engine are written in Python.
» Youtube is originally written in Python and mysql.
14. Slide 14 www.edureka.in/python
Users of Python
» Zope Corporation has developed Blue Bream (a
powerful Web application server) using Python
that's available as free software.
» Ultraseek Server, a commercial search engine
product, is implemented as an elaborate multi-
threaded Python program.
» The program contains over 11,000 lines of Python
code, and the user interface is implemented with
over 17,000 lines of Python-scripted HTML
» Shopzilla is a family of comparison shopping sites.
» Shopzilla uses Python for configuration
management and deployment, automated testing
and internal tool development.
» YUM, a package management utility for RPM-
compatible Linux operating systems is written in
15. Slide 15 www.edureka.in/python
Traditional Uses of Python
16. Slide 16 www.edureka.in/python
Uses of Python in Data Analytics
New use-cases of python are the major growth driver for the increasing demand for python skills.
These Use-cases are emerging because of various reasons. One of which is the new packages that were added into
the standard library such as Pydoop, Pandas, Scipy etc.
We will see how to use them in further sessions.
17. Slide 17 www.edureka.in/python
Python Users for Data Analytics
Used for weather forecasting by http://www.forecastwatch.com/
AppNexus a real-time online-advertising-platform company uses the Python
programming language to help conduct heavy-duty data analysis.
The company is a leading provider of multi-manager/multi-asset risk
management analytics. A complete Risk Management System is written in
Scientists in the Theoretical Physics Division at Los Alamos National Laboratory
are using Python to control large-scale physics codes on massively parallel
supercomputers, high-end servers, and clusters. Python plays a central role in
controlling these simulations, performing data analysis, and visualization.
18. Slide 18 www.edureka.in/python
January 1994 October 16, 2000 December 3, 2008
Python 1.0 Python 2.0 Version 3.0
Python 1.5 - December 31, 1997
Python 1.6 - September 5, 2000
Python 2.1 - April 17, 2001
Python 2.2 - December 21, 2001
Python 2.3 - July 29, 2003
Python 2.4 - November 30, 2004
Python 2.5 - September 19, 2006
Python 2.6 - October 1, 2008
Python 2.7 - July 3, 2010
Python 3.1 - June 27, 2009
Python 3.2 - February 20, 2011
Python 3.3 - September 29, 2012
Python 3.4 - March 16, 2014
19. Slide 19 www.edureka.in/python
In this course we are going to use Python version 2.7.6
It is because:
The library support for version 3.x is not adequate to fulfill day to day business needs.
In the industry, most of the softwares are using version 2.x and hence it is the most widely used version.
Python 2 or Python 3
20. Slide 20 www.edureka.in/python
21. Slide 21 www.edureka.in/python
22. Slide 22 www.edureka.in/python
Python is pre-installed on most Unix systems, including Linux and MAC OS X.
The pre-installed version is 2.x
You can check the version installed on machine by executing the below command:
Please refer the detailed Installation Guide available in the LMS.(You will find the installation guides under
Pythons Installation tab.)
How to get Python?
Note: We will be using Ubuntu virtual machine for practicals.
23. Slide 23 www.edureka.in/python
Getting Help in Python
Python interpreter has a built-in function called
help(‘Object’). This function is intended for interactive
use which invokes the help system.
To use this function, type- help() or help(‘Object’)
To exit the help press ‘q’
Run help(‘for') - This displays the help for the for
Run help() – This will open the help shell.
“help” in Version 2.x & 3.x
24. Slide 24 www.edureka.in/python
Pydoc is a documentation module for Python which gets installed with any Python distribution.
Pydoc allows programmers to access Python's documentation, generate HTML pages with documentation specifics,
and find the appropriate module for a particular job.
Pydoc can be accessed from a module-specific GUI from within the Python Interpreter, or from a command line shell.
Getting Help in Python(Contd.)
“pydoc” (needs to be executed on Terminal)
25. Slide 25 www.edureka.in/python
IDE is “Integrated Development Environment” which is used as the code editor, including a series of peripheral
components and attachments.
The most important feature of the Python IDE is beyond ordinary text editor, it offers a variety of language-specific
shortcut editing functions which make it fast and comfortable for programmers while coding.
The IDE that we will be using is Pycharm.
26. Slide 26 www.edureka.in/python
You can download Free Community Edition of Pycharm from the below link:
27. Slide 27 www.edureka.in/python
To start Python, all you need to do is type python into your command line.
From here on, the $ sign denotes the start of a terminal command line, and the # sign denotes a comment.
Python ignores anything written to the right of a # sign on a given line.
$ python # Type python into your terminal's command line
>>> # After a short message, the “>>>” symbol will appear. This signals the start of the Interpreter.
Starting “python” Interpreter
28. Slide 28 www.edureka.in/python
In addition to being a programming language, Python is also an interpreter. The interpreter reads other Python
programs and commands, and executes them.
Note that Python programs are compiled automatically before being scanned by the interpreter. The scanning process
is hidden which makes Python faster than a pure interpreter.
Once you're inside the Python interpreter, type in commands at will.
Using the Interpreter
29. Slide 29 www.edureka.in/python
Comments: Any text to the right of the # symbol is mainly useful as notes for readers.
Bulk Comments: Enclose the code in triple quoted strings (“””).
Literal Constants: Any number or string that represents itself.
Example: The number 2 always represents itself and nothing else - it is a constant because its value cannot be changed.
Comments and Literals
30. Slide 30 www.edureka.in/python
Python supports several different numeric types:
Examples: 0, 1, 1234, -56
Integers are implemented as C longs
Note: Dividing an integer by another integer will return only the integer part of the quotient, e.g. typing 7/2 will yield 3.
Must end in either l or L
Can be arbitrarily long
Floating point numbers
Examples: 0., 1.0, 1e10, 3.14e-2, 6.99E4
Implemented as C doubles
Division works normally for floating point numbers: 7./2. = 3.5
Operations involving both floats and integers will yield floats:
6.4 – 2 = 4.4
Types of Numbers
31. Slide 31 www.edureka.in/python
Examples: 0177, -01234
Must start with a leading 0
Examples: 0x9ff, 0X7AE
Must start with a leading 0x or 0X
Examples: 3+4j, 3.0+4.0j, 2J
Must end in j or J
Typing in the imaginary part first will return the complex number in the order Re+ImJ
Types of Numbers
32. Slide 32 www.edureka.in/python
Python Identifiers: Rules for Variable names
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 is a case sensitive programming language.
Python does not allow special characters such as @, $ and % within identifiers.
Variables are used by just assigning them a value. No declaration or data type definition is needed/used.
Identifier naming convention for Python
Class names start with an uppercase letter and all other identifiers with a lowercase letter.
Starting an identifier with a single leading underscore indicates by convention that the identifier is meant to be
Starting an identifier with two leading underscores indicates a strongly private identifier.
If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
33. Slide 33 www.edureka.in/python
My name is Annie.
I love quizzes and
puzzles and I am here to
make you guys think and
answer my questions.
34. Slide 34 www.edureka.in/python
1. Which one of the below Identifiers is incorrect?
35. Slide 35 www.edureka.in/python
$var is incorrect. It is because in python one cannot start the name of the
identifier with special character.
36. Slide 36 www.edureka.in/python
Basic algebraic operations
Four arithmetic operations: a+b, a-b, a*b, a/b
Modulo : a%b
Other elementary functions are not part of standard Python,
but included in packages like NumPy and SciPy
Greater than, less than, etc.: a < b, a > b, a <= b, a >= b
Identity tests: a == b, a != b
Operations on Numbers
37. Slide 37 www.edureka.in/python
2. When a = 5 and b = 2 then, what will be the value of
(a*3*b) < (((a*b)-(b*b))/b)*(a*b) ?
38. Slide 38 www.edureka.in/python
The answer is False. It is because the value of left expression ( (a*3*b) ) and
the right expression ( (((a*b)-(b*b))/b)*(a*b) ) are equal.
(a*3*b) = (((a*b)-(b*b))/b)*(a*b) = 30
39. Slide 39 www.edureka.in/python
Bitwise OR : a | b
Bitwise and: a & b
Bitwise exclusive or: a ^ b
Operations on Numbers(Contd.)
OR Operator AND Operator XOR Operator
Shift a left or right by b bits: a << b, a >> b
Left Shift Operator 5 places to the left
Right Shift Operator
40. Slide 40 www.edureka.in/python
3. What is the output of ( 2 | 4 ), ( 2 & 4 ), and ( 2 ^ 4 ) respectively?
A. 6, 0 and 6
B. 6, 6 and 6
C. 0, 6 and 6
D. 6, 0 and 0
41. Slide 41 www.edureka.in/python
The answer is 6, 0 and 6.
42. Slide 42 www.edureka.in/python
In Addition to other Operators:
Not surprisingly, Python follows the basic PEMDAS
(Parentheses, Exponents, Multiplication, Division,
Addition, Subtraction) order of operations.
Python supports mixed-type math. The final answer will
be of the most complicated type used.
Operations on Numbers(Contd.)
43. Slide 43 www.edureka.in/python
4. What is the output of ( 100 * 20 ** 2 / 4 ) ?
44. Slide 44 www.edureka.in/python
The answer is 10000.
According to PEMDAS, exponent will be calculated firstt, then multiplication
will done and finally division.
The expression ( 100 * 20 ** 2 / 4 ) is evaluated as:
( ( 100 * (20 ** 2) ) / 4 )
= (( 100 * 400 ) / 4)
= ( 40000 / 4 )
45. Slide 45 www.edureka.in/python
Python does not support a character type; these are
treated as strings of length one, thus also considered a
Strings are immutable.
Strings are ordered blocks of text
Strings are enclosed in single or double quotation
Double quotation marks allow the user to extend strings
over multiple lines without backslashes, which usually
signal the continuation of an expression.
Examples: 'abc', “ABC”.
Concatenation and repetition
Strings are concatenated with the + sign:
Strings are repeated with the * sign:
Operations on Strings - I
46. Slide 46 www.edureka.in/python
Indexing and Slicing Operation
Python starts indexing at 0.
A string s will have indexes running from 0 to len(s)-1 (where len(s) is the length of s) in integer quantities.
s[i] fetches the ith element in s.
Operations on Strings - II
47. Slide 47 www.edureka.in/python
In - Returns true if a character exists in the given string.
not in - Returns true if a character does not exist in the given string.
String Formatting Operator: %
This operator is unique to strings and makes up for the pack of having functions from C's printf() family.
Operations on Strings- III
48. Slide 48 www.edureka.in/python
capitalize(): Capitalizes first letter of string.
count(str, beg= 0,end=len(string)): Counts how
many times str occurs in string or in a substring of
string if starting index beg and ending index end
encoded string version of string; on error, default is
to raise a ValueError unless errors is given with
'ignore' or 'replace‘.
the string using the codec registered for Encoding.
Encoding defaults to the default string encoding.
index(str, beg=0, end=len(string)): Same as find(),
but raises an exception if str not found.
Built-in String Methods
49. Slide 49 www.edureka.in/python
max(str): Returns the max alphabetical character
from the string str.
min(str): Returns the min alphabetical character
from the string str.
replace(old, new [, max]): Replaces all occurrences
of old in string with new or at most max
occurrences if max given.
upper(): Converts lowercase letters in string to
More String Methods
50. Slide 50 www.edureka.in/python
Leading whitespace (spaces and tabs) at the beginning of
a logical line is used to compute the indentation level of
the line, which in turn is used to determine the grouping
Indentation is MUST in Python
There are no braces to indicate blocks of code for class
and function definitions or flow control.
Blocks of code are denoted by line indentation, which is
The number of spaces in the indentation is variable,
but all statements within the block must be indented
the same amount.
Standard is to use 4 whitespaces as per official
Some editors automatically takes care of the
51. Slide 51 www.edureka.in/python
Python scripts are written in text files with the suffix “.py”. The scripts can be read by the interpreter in several ways:
Running a Python Script
$ python script.py
# This will simply execute the script and return to the terminal afterwards
Example Script “commands.py”
Execution of “commands.py”
52. Slide 52 www.edureka.in/python
Write a program to print the:
» Number of lowercase “a” and “o” in the following sentence.
» Number of uppercase “L” and “N” in the following sentence.
‘Discover, Learning, with, Edureka’
Write a program to remove the following from:
» Remove all w’s before and after .edureka.
» Remove all lowercase letter before and after .edureka.
» Remove all printable characters
53. Slide 53 www.edureka.in/python
Identify the type of numbers:
Write a program for String Formatting Operator % which should include the following conversions:
» Signed decimal integer
» Octal integer
» Hexadecimal integer (UPPERcase letters)
» Floating point real number
» Exponential notation (with lowercase 'e')
54. Slide 54 www.edureka.in/python
Basic idea about different sequences:
Getting to know file operations:
55. Slide 55 www.edureka.in/python
A good set of information to begin with can be found at:
Official documentation page:
For more on loops:
56. Slide 56 www.edureka.in/python
What’s within the LMS
Click here to
expand and view
all the elements
of this Module
57. Slide 57 www.edureka.in/python
What’s within the LMS