100% found this document useful (1 vote)
365 views21 pages

Python Programming Session

Python is a multi-purpose programming language that is interpreted, dynamically typed and supports object-oriented, imperative and functional programming styles. It emphasizes code readability through features like indentation and allows programmers to express concepts in fewer lines of code than languages like C++ or Java. The document introduces Python syntax including indentation, control structures like conditionals and iterations, built-in data types like strings, lists, dictionaries, sets and tuples. It also covers functions, lambda functions and compares Python and C++ code that reverses a string. In closing, the document notes some applications of Python like web development, GUI programming, scientific computing and more.

Uploaded by

Ambika Singhal
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
100% found this document useful (1 vote)
365 views21 pages

Python Programming Session

Python is a multi-purpose programming language that is interpreted, dynamically typed and supports object-oriented, imperative and functional programming styles. It emphasizes code readability through features like indentation and allows programmers to express concepts in fewer lines of code than languages like C++ or Java. The document introduces Python syntax including indentation, control structures like conditionals and iterations, built-in data types like strings, lists, dictionaries, sets and tuples. It also covers functions, lambda functions and compares Python and C++ code that reverses a string. In closing, the document notes some applications of Python like web development, GUI programming, scientific computing and more.

Uploaded by

Ambika Singhal
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 21

INTRODUCTION TO

PYTHON PROGRAMMING
WHY PYTHON?
MULTIPURPOSE (Web , GUI, Scripting etc.)
Object Oriented
Interpreted
Strongly Typed and Dynamically Typed
Focus on Readability and Programmability
SYNTAX
INDENTATION

 Most languages like C, C++ , JAVA etc. don’t care


about indexing. Curly braces are used to separate the
blocks of code.
 Indentations make the code more readable , separates
and groups the different blocks of the code.
Sample Code
CONTROL STATEMENTS
 There are two different types of control statements which change the
normal execution of the program.
 Conditional Statements
 Iteration Statements
 In control statements, indentation plays a major role.
Conditional Statements
 Conditional Statements are used to execute a particular
block of statements on the basis of the result of a
specified condition.
 Arithmetic and Logical Operators can be used to create
conditions.
 For eg., Assigning the grades of a student on the basis of
the marks scored, checking if a person is above 18 years
and thus check his eligibility to vote etc.
ITERATION STATEMENTS
 The iteration statements are used to repeat a specified
block of code multiple times , on the basis of the result of
a given condition.
 The three most widely used iteration statements or loops
in Python are:
For Loop
While Loop
Strings in Python
Strings refers to a collection of characters .
It is specified within double or single quotes.
Strings in python are immutable.
However, Python provides us with several inbuilt
functions to manipulate strings and get the
desired results.
 STRING CONCATENATION: Joining two are more different strings.

 STRING INDEXES:

 STRING SLICING: It is used to retrieve a slice/part if the string.


 find(): It is used to find the first instance of a substring in
the given string. If no instance is found -1 is returned.

 isupper(): It is used to check whether all the characters


of the string are uppercase or not.

 len(): It is used to find the length of the given string.


DATA STRUCTURES IN PYTHON

There are some in-built functions in python which


can be used for storing and retrieving data.
These are:
Lists
Dictionaries
Sets
Tuples
LISTS
 A list in python is used to store a collection of related
data.
 For eg., If we need to store the ages of a group of
students, instead of storing the in separate variables, we
can store them in a list.
 All the elements stored in a list can be of different data
types.
For e.g, l =[‘vit’,10,’10.98’] is a valid list in python
LIST MANIPULATION
 Some of the in-built methods to manipulate strings are:
append(): Add an element of the end list.
count(): Returns the count of the number of items passed as an argument.
remove(): Removes a particular element in a group.
sort(): Sorts the elements of the list in ascending order.
extend(): This method adds the elements of on list to other.
insert(): Insert an element at a specific index in the list.
pop(): Deletes a particular element in the list. If no element is specified,
the last element is deleted. In addition to deletion, the specified
element is printed by this method
DICTIONARIES
 A dictionary is collection of related data PAIRS.
 The general syntax is:
dictionaryName: {dictionaryKey: data}
the same dictionary key cannot be reused.
 A dictionary can also be declared using the dict()
function.
 Dictionaries like lists are mutable.
DICTIONARIES MANIPULATION
 Adding elements in the dictionary:
Items can be added in the dictionary using the following syntax:
dictionaryName[‘newKey’] = “value”
 Removing/Deleting elements in the dictionary:
Items can be deleted as follows:
del dictonaryName[‘dictionaryKey’]
SETS
Sets are like lists except for the fact that
they store only unique elements and
eliminate the duplicates.
A list can be converted into set to remove
duplicate elements.
Frozensets are immutable counterparts od
sets.
TUPLE
Tuples are immutable lists.
Unlike lists, the tuples are enclosed within
round parenthesis.
Tuples are thought of as immutable lists.
FUNCTIONS
 Python has flexibility to define and can use them in the program.
 This prevents data redundancy and improves the structure of our code ,
making it more readable .
 The syntax for defining our own functions in python is :
def functionName(parameters):
//code for what the function should do
return [expression]
 The function might or might not accept parameters
 The functions can be called anytime in the code using :
functinName([parameters])
LAMBDA FUNCTIONS
 Lambda functions are used to create small , one-time and anonymous
function objects in python.
 It can have any number of parameters.
 For e,g,
COMPARISON IN CPP AND PYTHON CODE
(PROGRAM TO REVERSE A STRING)

PYTHON

CPP
APPLICATIONS OF PYTHON

You might also like