0% found this document useful (0 votes)
41 views

TO Python: Dr. S. Selvakanmani, Associate Professor, Department of Cse, Velammal I Tech

Python Unit 1 PPT
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)
41 views

TO Python: Dr. S. Selvakanmani, Associate Professor, Department of Cse, Velammal I Tech

Python Unit 1 PPT
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
You are on page 1/ 36

INTRODUCTION

TO
PYTHON
Dr. S. SELVAKANMANI,
ASSOCIATE PROFESSOR,
DEPARTMENT OF CSE,
VELAMMAL I TECH
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
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)
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.
PYTHON – INTRODUCTION Contd..
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.
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.
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
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)
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.
PYTHON – INTERACTIVE MODE

>>> - Chevron
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.


PYTHON – SCRIPT MODE
PYTHON – FEATURES OF IDLE

 Multi-window text editor with syntax highlighting.

 Auto completion with smart indentation.

 Python shell to display output with syntax highlighting.


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
PYTHON – JUPYTER NOTEBOOK
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
PYTHON – JUPYTER NOTEBOOK
PYTHON – INTERACTIVE Vs SCRIPT MODE
PYTHON – VIRTUAL ENVIRONMENT

 https://repl.it
 colab.research.google.com
 https://www.codechef.com/ide
 https://pynative.com/online-python-code-
editor-to-execute-python-code/
 https://www.jdoodle.com/python3-
programming-online/
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')
PYTHON – LIST OF KEYWORDS : 33 nos.
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.
PYTHON – SYNTAX

 Eg: Names like myClass, var_1, and


this_is_a_long_variable
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).
Use the semicolon ; to write multiple
 Eg1: msg="Hello World"
statements in a single line.
 Eg2: code=123 Eg:
msg='"Hello World";code=123;name="Steve"'
 Eg3: name="Steve"
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"
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.
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.
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 : Use triple – quote
for mutli – line
# this is a comment
comment
print ("Hello World")
print ("Welcome to Python Tutorial") #this is also a comment but after a statement
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”) A function is a block of
code which only runs
 Eg:
when it is called.
>>> x=input("enter the name:") A set of statements
enter the name: George which perform a
>>>y=int(input("enter the number")) specific tasks.
 enter the number 3
Python accepts string as default data type. Conversion is required for type.
PYTHON – INPUT AND OUTPUT

 OUTPUT: Output can be displayed to the user using print


statement .
 Syntax:
print (expression/constant/variable)
 Example:
>>> print ("Hello")
Hello
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
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.
THANK
YOU

You might also like