2. AGENDA
Companies using Python
Top languages for Data Science
Introduction to Python & Features
Installation of Python
Working in IDLE
Working in Jupyter Notebook
Interactive Vs Script Mode
3.
4.
5. PYTHON - INTRODUCTION
Developed in late 1980 by Guido Van Rossum at National
Research Institute for Mathematics and Computer Science
in Netherlands.
Features of Python:
Simple – It is simple to learn, read and write
High level language – Program codes contains easy to
read syntax that is later converted into a low level language
(i.e binary codes)
6. PYTHON – INTRODUCTION Contd..
Open Source – It is freely available and the source code is
available for free.
Cross Platform/Portable - Python can run equally on
different platforms such as Windows, Linux, Unix, and
Macintosh etc.
Interpreted Language – Python program written will be
converted into intermediate language which is again
translated into native or machine language for execution.
8. PYTHON – INTRODUCTION Contd..
Interpreter translates just one statement of the program at
a time into machine code.
Vs
Compiler scans the entire program and translates the
whole of it into machine code at once.
9. PYTHON – INTRODUCTION Contd..
Case – Sensitive Language – Difference between
Uppercase and lowercase letters. i.e area, Area.
Object Oriented Language - Python structures a
program by bundling related properties and behaviors into
individual objects.
Automatic Type Inference – Doesn‟t need to define the type
of the data during its declaration.
10. PYTHON – INTRODUCTION Contd..
Scripting language – Uses an Interpreter to translate its
source code. The interpreter reads and executes each line of
code one at a time (like a “script” in a play/audition)
No worry about memory allocation
Interface with existing programming language –
Comes with a large standard library that supports many
common tasks.
No Semicolon at the end of the statement
11. PYTHON – INSTALLATION
Downloads available in www.python.org (Known as Cpython
Installation and it comes with Python Interpreter , Python IDLE
and PIP ( Package Installer )
Other Python distributions available in Anaconda Python
distribution (https://www.anaconda.com/distribution/),
comes with preloaded packages such as NumPy , SciPy, Pandas
etc .
Other Popular downloads available in form of Spyder IDE ,
PyCharm IDE etc.. (https://www.guru99.com/python-ide-code-
editor.html)
12. PYTHON – WORKING IN IDLE
IDLE – Integrated Development and Learning Environment
Two modes of working : (i) Interactive mode and (ii) Script
mode
Interactive Mode : Writing & Executing one command at
a time. ( Click Start – All Programs – Python x.x –IDLE )
Type the commands in the prompt (>>>) and hit Enter to
see the output.
14. PYTHON – WORKING IN IDLE
Script Mode : Writing & Executing Programs.
(Click Start – All Programs – Python x.x – IDLE )
( Click File – New – in Python IDLE shell )
Type the commands in the newly opened window and save the
program with the extension (.py )
For Execution , Click Run – Run Module or Press F5.
16. PYTHON – FEATURES OF IDLE
Multi-window text editor with syntax highlighting.
Auto completion with smart indentation.
Python shell to display output with syntax highlighting.
17. PYTHON – WORKING IN JUPYTER NOTEBOOK
Launch Anaconda Navigator from Start – All Programs –
Anaconda –Anaconda Navigator .
Click on Launch JUPYTER Notebook (Opens in Web
Browser)
Select Python3 by clicking on the drop down arrow mark of
New Option placed on the right hand side of the Dashboard.
JUPYTER = JUlia, PYThon and R
19. PYTHON – WORKING IN JUPYTER NOTEBOOK
In this window, the code can be written within the cell
provided.
If using Interactive mode, Type the commands in the Cell
and Press Run or Shift Enter.
If using Script mode, Type the commands in the Cell , save
the file by clicking on Untitled1 , Click Run to run your
program
23. PYTHON – SYNTAX
Keywords – Set of predefined words. A prescribed rule of
usage for each keyword is called a syntax.
Python 3.x interpreter has 33 keywords defined in it.
Since they have a predefined meaning attached, they cannot
be used for any other purpose.
To know the list of python keywords:
>>>help('keywords')
25. PYTHON – SYNTAX
Apart from Keywords, Python program can have variables,
functions, classes, modules, packages etc.
Identifier is the name given to these programming elements.
An identifier should start with either an alphabet letter (lower or
upper case) or an underscore (_).
After that, more than one alphabet letters (a-z or A-Z), digits (0-
9) or underscores may be used to form an identifier.
No other characters are allowed such as @,#,$, etc
Identifiers are case – sensitive.
26. PYTHON – SYNTAX
Eg: Names like myClass, var_1, and
this_is_a_long_variable
27. PYTHON – STATEMENT
By default, the Python interpreter treats a piece of text
terminated by hard carriage return (i.e new line character) as one
statement.
It means each line in a Python script is a statement.
(Just as in C/C++/C#, a semicolon ; denotes the end of a
statement).
Eg1: msg="Hello World"
Eg2: code=123
Eg3: name="Steve"
Use the semicolon ; to write multiple
statements in a single line.
Eg:
msg='"Hello World";code=123;name="Steve"'
28. PYTHON – STATEMENT
Continuation of Statement: We can show the text spread over
more than one lines to be a single statement by using the
backslash () as a continuation character.
Eg:
msg="Hello Python Learners <enter>
Welcome to Python Tutorial <enter>
from CSE Department"
29. PYTHON – INDENTS
Many times it is required to construct a block of more than one
statements.
For example there might be multiple statements that are part of
the definition of a function or method.
Most of the programming languages like C, C++, Java use braces
{ } to define a block of code. But, python uses indentation.
Blocks of code are denoted by line indentation.
It is a space given to the block of codes for class and
function definitions or flow control.
30. PYTHON – INDENTS
When a block is to be started, type the colon symbol (:) and
press Enter.
Any Python-aware editor (like IDLE) goes to the next line
leaving an additional whitespace (called indent).
Subsequent statements in the block follow the same level of
indent.
31. PYTHON – COMMENTS
A hash sign (#) is the beginning of a comment.
Anything written after # in a line is ignored by interpreter.
Eg: percentage = (minute * 100) / 60 # calculating
percentage of an hour
Python does not have multiple-line commenting feature. You
have to comment each line individually as follows :
# this is a comment
print ("Hello World")
print ("Welcome to Python Tutorial") #this is also a comment but after a statement
Use triple – quote
for mutli – line
comment
32. PYTHON – INPUT AND OUTPUT
Input is data entered by user (end user) in the program.
In python, input () function is available for input.
Syntax is:
variable = input (“data”)
Eg:
>>> x=input("enter the name:")
enter the name: George
>>>y=int(input("enter the number"))
enter the number 3
Python accepts string as default data type. Conversion is required for type.
A function is a block of
code which only runs
when it is called.
A set of statements
which perform a
specific tasks.
33. PYTHON – INPUT AND OUTPUT
OUTPUT: Output can be displayed to the user using print
statement .
Syntax:
print (expression/constant/variable)
Example:
>>> print ("Hello")
Hello
34. PYTHON – VARIABLE
Any value of certain type is stored in the computer's memory for
processing.
Out of available memory locations, one is randomly allocated for
storage.
In order to conveniently and repeatedly refer to the stored value,
it is given a suitable name.
A value is bound to a name by the assignment operator '='.
Eg:
A = 3
35. PYTHON – VARIABLE
Eg:
A = 3
A is the identifier and 3 is the value assigned to it.
The same identifier can be used to refer to another value.
Eg:
A = „hello‟
So, the value being referred can change (or vary), hence it is
called a variable.
It is important to remember that a variable is a name given
to a value, and not to a memory location storing the value.