Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

Introduction to PYTHON

Archit A. Vohra
About Python
 Guido Van Rossum.

 First released in 1991.

 Guido van Rossum named the language after the BBC


comedy series “Monty Python's Flying Circus”.

 1994 : Version(1), 2000 : Version(2), 2008 : Version(3)

 Since January, 2018 one of the most popular


programming language.
About Programming Languages
 High Level Vs. Low Level.
About Programming Languages
 Procedure Oriented / Object Oriented.
About Programming Languages
 Compiled / Interpreted
Application area of Programming Languages
Application area of C, C++, JAVA
 Operating System (Unix - C), Compilers,

 Embedded Systems – Digital Camera, Vehicles, Home Security (sensors),

 Web Browsers : Mozilla Firefox uses C++

 Adobe Photoshop – C++

 Text editors, network drivers, utilities are all developed using C.

 Gmail, Eclipse uses JAVA.


Application area of Python
 In YouTube Python is used as scripting as well as programming language.

 Google extensively uses Python in web search systems.

 Dropbox uses Python on server as well as client.

 NASA (National Aeronautics and Space Administration) uses Python for


scientific programming task.

 NSA uses Python for Cryptography and intelligence analysis.


Features of Python
 Simple & Easy to learn.

 Free & open source.

 High level language.

 Interpreted.

 Supports Procedure oriented & Object Oriented programming.

 Extensible, Embeddable.
Installing Python
 Current version of Python 3.9.7 or 3.10

 Previous stable and most popular releases: 2.7 & 3.7.

 Check your Computer System configuration before installing Python.

 https://www.python.org/downloads/

 Any version beyond 3.7 can be installed.

 https://colab.research.google.com/notebooks/intro.ipynb (mobile browser)


Getting started with Python – Printing Text
 Printing name without print(), two times, multiple times.

 print() is used to print text.

 Single, Double & Triple Quotes, Quotes within quotes.

 Escape Sequences \ .

 Raw string.

 Getting help on print command, parts of print.


Variables in Python
 Variables are examples of identifiers. Identifiers are names given to
identifying something.

 The first character of identifier must be a alphabet or ‘_’ (underscore).

 The rest of the identifier name can consist of alphabet, number or ‘_’.

 Identifier names are case sensitive.

 Variable and its address, multiple variables with same value.

 Getting value of variable from user.


Data types in Python
 Variables can hold values of different types called data types.

 The basic types are numbers and strings.

 Python has the following data types built-in by default, in these categories:
 Text Type: str
 Numeric Types: int, float, complex
 Sequence Types: list, tuple, range
 Mapping Type: dictionary
 Set Types: set, frozenset
 Boolean Type: bool
 Binary Types: bytes, bytearray, memoryview
Operators in Python
 Arithmetic Operators : **, %, //.

 Assignment Operators :

- Assigning values to multiple variables.

 Comparison / Relational Operators :

 Logical Operators :

 Bitwise Operators : & , |, ^


Complex Numbers in Python
 A Complex Number is a combination of a Real Number and an Imaginary
Number.

 Examples of real number includes 4, 12.87, -6, 3/5, √2; Most of the numbers
are real numbers.

 Imaginary numbers when squared give a negative result. j= √-1.

 Hence the numbers line 3j, 8+j etc. are complex numbers.
Strings in Python
 String literals in python are surrounded by either single quotation marks, or
double quotation marks.

 “”” (triple quotes) are used to assign multiple line of text to a string.

 Indexing in strings can be managed using [ ].

 Slicing of strings can be used to fetch substring from within a string.

 Length of the string can be found out using the len() function.

 Some common string methods include: upper(), lower(), replace()

 format() method can be used to concate numbers with strings.


Lists in Python
 The most basic data structure in Python is the sequence. Each element of a
sequence is assigned a number - its position or index starting from 0 (zero).
 The most versatile is the list, which can be written as a list of comma-separated
values (items) between square brackets.
 Lists might contain items of different types, but usually the items all have the
same type.
 The values of the list can be accessed through index numbers and slicing.
 ‘del’ along with indexing can be used to remove elements from a list.
 A list can consist of multiple existing lists.
Lists in Python
 Most common functions applicable on list include: len(), min() & max().
 Most common methods applicable on list include: append, count, extend, index,
insert, pop, remove, reverse and sort.
 List in python are mutable.
Basics while writing program in Python
 Indentation needs to be strictly followed.

 To get any kind of data from user the input() can be used.

 For single line comment use the symbol ‘#’.

 In case of multiple line comments include multiple lines within ‘’’ :


‘’’
Example of multiple
Line comments
‘’’
Control Flow in Python (Mainly - Branching & Looping)
BRANCHING:

If <condition1>:

<statements if condition1 is true>

elif <condition2>:

<statements if condition2 is true>

……….

else:

<statements if none of the conditions are true>

You might also like