Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Chapter 8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 117

Subject :Programming Semester: I

and problem solving

Chapter 8:Introduction to python

1. Basic elements of python.


2. Input, output statements.
3. Control Structure.
1. Branching program.(flow control statements)
2. Iteration(loops)

Faculty: Komal Waykole


1
Why python?
 Scripting language.
 Highly readable.
 Few syntactical constructions.
 Mostly used for web development domain.

Faculty: Komal Waykole


2
Characteristics of Python
 Supports functional and structured programming
methods as well as OOP.
 used as a scripting language (can be compiled to byte-code
(portable code)for building large applications.)
 provides very high-level dynamic data types.
 supports dynamic type checking( It means that the type of
a variable is allowed to change over its lifetime.)
 supports automatic garbage collection.
 easily integrated with C, C++, COM, ActiveX, CORBA, and
Java.

Faculty: Komal Waykole


3
Features of Python…
1. Easy-to-learn − Python has few keywords, simple
structure, and a clearly defined syntax. This allows the student
to pick up the language quickly.
2. Easy-to-read − Python code is more clearly defined and
visible to the eyes.
3. Easy-to-maintain − Python's source code is fairly easy-to-
maintain.
4. A broad standard library − Python's bulk of the library is
very portable and cross-platform compatible on UNIX,
Windows, and Macintosh OS.

Faculty: Komal Waykole


4
Features of Python…
1. Portable − Python can run on a wide variety of hardware
platforms and has the same interface on all platforms.
2. Extendable − You can add low-level modules to the Python
interpreter. These modules enable programmers to add to or
customize their tools to be more efficient.
3. Databases − Python provides interfaces to all major
commercial databases.
4. GUI Programming − Python supports GUI applications
that can be created and ported to many system calls, libraries
and windows systems.
5. Scalable − Python provides a better structure and support
for large programs than shell scripting.

Faculty: Komal Waykole


5
Advantages of Python
 Interpreted Language:
 processed at runtime by the interpreter.
 not need to compile your program before executing it.
 Interactive:
 interact with the interpreter directly to write your programs.
 Object-Oriented:
 supports Object-Oriented style
 Or technique of programming that encapsulates code within objects.
 a Beginner's Language :
 the beginner-level programmers.
 supports the development of a wide range of applications from simple
text processing to WWW browsers to games.

Faculty: Komal Waykole


6
Application of Python…
 GUI based desktop applications
 Graphic design, image processing applications, Games, and
Scientific/ computational Applications
 Web frameworks and applications
 Enterprise and Business applications
 Operating Systems
 Education
 Database Access
 Language Development
 Prototyping
 Software Development

Faculty: Komal Waykole


7
C-programming v/s Python

Faculty: Komal Waykole


8
C-programming v/s Python
C Python

C programs are saved with .c Python programs are saved by .py


extension. extension.

C is a compiled language. Python is an interpreted language.

Variables are declared in C. Python has no declaration.

Pointers are available in C No pointers functionality is


language. available in Python.
Faculty: Komal Waykole
9
Keywords
 Keywords are the reserved words in Python.
 keyword cannot be used as
a variable name, function name or any other
identifier.
 They are used to define the syntax and
structure of the Python language.
 keywords are case sensitive.
 Eg: This means, Variable and variable are not the same.
All the keywords except True, False and None are in lowercase and they
must be written as they are.

Faculty: Komal Waykole


10
Keywords …
The list of all the keywords is given below.

Faculty: Komal Waykole


11
Identifier
 An identifier is a name given to entities like class,
functions, variables, etc. It helps to differentiate
one entity from another.
 Identifiers can be a combination of letters in
lowercase (a to z) or uppercase (A to Z) or
digits (0 to 9) or an underscore(_).
 Names like myClass, var_1 and print_this_to_screen, all are
valid example.
 An identifier cannot start with a digit.
 Eg: 1variable is invalid, but variable1 is a valid name.

Faculty: Komal Waykole


12
Identifier….
Keywords cannot be used as identifiers.

We cannot use special symbols like !, @, #, $, % etc. in


our identifier.

Faculty: Komal Waykole


13
Identifier….
 We cannot use special symbols
like !, @, #, $, % etc. in our identifier.
 An identifier can be of any length.

Faculty: Komal Waykole


14
Identifier….
• Always give the identifiers a name that makes
sense.

• Eg: While c = 10 is a valid name, writing count =


10 would make more sense, and it would be easier
to figure out what it represents when you look at
your code after a long gap.

Faculty: Komal Waykole


15
Statements
 Instructions that a Python interpreter can execute are called
statements.
 For example, a = 1 is an assignment statement. if statement,
for statement, while statement, etc. are other kinds of
statements.
 Multi-line statement:
 the end of a statement is marked by a newline character. But we
can make a statement extend over multiple lines with the line
continuation character (\).
 Eg: a = 1 + 2 + 3 + \
4+5+6+\
7+8+9
Faculty: Komal Waykole
16
Statements….
 line continuation is implied inside parentheses ( ),
brackets [ ], and braces { }.
 Eg: a = (1 + 2 + 3 +
4+5+6+
7 + 8 + 9)
 Eg: colors = ['red',
'blue',
'green’]
 multiple statements in a single line using semicolons.
 Eg: a = 1; b = 2; c = 3

Faculty: Komal Waykole


17
Variable
 A variable is a named location used to store data in the
memory.
 It is helpful to think of variables as a container that holds data
that can be changed later in the program.
 For example,Eg: number = 10
 You can think of variables as a bag to store books in it and
that book can be replaced at any time.
 Eg: number = 10
number = 1.1
 Initially, the value of number was 10. Later, it was changed to
1.1.

Faculty: Komal Waykole


18
Variable
 Declaring and assigning value to a variable
 Eg: website = "apple.com"
print(website)
 Output:
apple.com
 Changing the value of a variable
 Eg: website = "apple.com"
print(website)
# assigning a new value to website
website = "programiz.com"
print(website)
 Output
apple.com
programiz.com

Faculty: Komal Waykole


19
Variable…
 Assigning multiple values to multiple variables
 Eg: a, b, c = 5, 3.2, "Hello"
print (a)
print (b)
print (c)
 If we want to assign the same value to multiple variables at
once, we can do this as:
 Eg: x = y = z = "same"
print (x)
print (y)
print (z)

Faculty: Komal Waykole


20
constant
 A constant is a type of variable whose value cannot be
changed.
 It is helpful to think of constants as containers that hold
information which cannot be changed later.
 constants are usually declared and assigned in a module.
 Here, the module is a new file containing variables,
functions, etc which is imported to the main file.
 constants are written in all capital letters and underscores
separating the words.

Faculty: Komal Waykole


21
constant
 Declaring and assigning value to a constant
 Eg: Create a constant.py:
PI = 3.14
GRAVITY = 9.8
 Create a main.py:
import constant
print(constant.PI)
print(constant.GRAVITY)
 Output
3.14
9.8

Faculty: Komal Waykole


22
Literals
 Literal is a raw data given in a variable or constant. In
Python, there are various types of literals they are as
follows:
1. Numeric Literals
2. String Literals
3. Boolean literals
4. Special literals
5. Literal collection
1. List literals,
2. Tuple literals,
3. Dict literals, and
4. Set literals.
Faculty: Komal Waykole
23
Numeric Literals
 Numeric Literals are immutable (unchangeable).
 Numeric literals can belong to 3 different numerical types:
 Integer,
 Float, and
 Complex.

Faculty: Komal Waykole


24
Numeric Literals example…

Faculty: Komal Waykole


25
String Literals
 A string literal is a sequence of characters
surrounded by quotes.
 We can use both single, double, or triple quotes
for a string.
 a character literal is a single character
surrounded by single or double quotes.

Faculty: Komal Waykole


26
String Literals Example

Faculty: Komal Waykole


27
Boolean literals
 A Boolean literal can have any of the two values: True or
False.
 True represents the value as 1 and False as 0.

Faculty: Komal Waykole


28
Special literals…
 Python contains one special literal i.e. None. We use it to
specify that the field has not been created.

Faculty: Komal Waykole


29
Literal Collections
 There are four different literal collections
 List literals- mutable, repetition allowed, ordered
 Tuple literals- immutable , repetition allowed,
ordered
 Dict literals- mutable, no repetition, unordered
 Set literals.- mutable, no repetition,ordered

Faculty: Komal Waykole


30
Python Datatypes(literals)
 Numbers
 Interger
 Floating point
 Complex number
 List
 Tuple
 Strings
 Set
 Dictionary

Faculty: Komal Waykole


31
Python List
 List is an ordered sequence of items.
 It is one of the most used datatype in Python and is very
flexible.
 All the items in a list do not need to be of the same type.
 Declaring a list is pretty straight forward. Items separated
by commas are enclosed within brackets [ ].
 The values stored in a list can be accessed using the slice
operator ([ ] and [:]) with indexes starting at 0 in the beginning
of the list and working their way to end -1.
 The plus (+) sign is the list concatenation operator, and the
asterisk (*) is the repetition operator.
 Lists are mutable, meaning, the value of elements of a list can
be altered.
Faculty: Komal Waykole
32
Python List eaxmple….

Faculty: Komal Waykole


33
Python List example….
 Lists are mutable, meaning, the value of elements of a list can
be altered.

Faculty: Komal Waykole


34
Python Tuple
 Tuple is an ordered sequence of items same as a list.
 The only difference is that tuples are immutable. Tuples once
created cannot be modified.
 Tuples are used to write-protect data and are usually faster
than lists as they cannot change dynamically.
 It is defined within parentheses ( ) where items are
separated by commas.
 We can use the slicing operator [ ] to extract items but
we cannot change its value.

Faculty: Komal Waykole


35
Python Tuple example

Faculty: Komal Waykole


36
Python Strings
 String is sequence of Unicode characters.
 We can use single quotes or double quotes to represent
strings.
 Multi-line strings can be denoted using triple quotes, '''
or """.
 the slicing operator [ ] can be used with strings.
Strings, however, are immutable.

Faculty: Komal Waykole


37
Python Strings Example

Faculty: Komal Waykole


38
Python Set
 Set is an unordered collection of unique items.
 Set is defined by values separated by comma inside braces
{ }.
 Items in a set are not ordered.
 We can perform set operations like union, intersection
on two sets.
 Sets have unique values. They eliminate duplicates.
 Set are unordered collection, indexing has no
meaning. Hence, the slicing operator [] does not
work.

Faculty: Komal Waykole


39
Python Set example

Faculty: Komal Waykole


40
Python Dictionary
 Dictionary is an unordered collection of key-value
pairs.
 It is generally used when we have a huge amount of data.
 Dictionaries are optimized for retrieving data.
 We must know the key to retrieve the value.
 In Python, dictionaries are defined within braces {} with
each item being a pair in the form key:value.
 Key and value can be of any type.
 We use key to retrieve the respective value. But not
the other way around.

Faculty: Komal Waykole


41
Python Dictionary Example

Faculty: Komal Waykole


42
Compare list, tuple, set, dictionary

Faculty: Komal Waykole


43
Compare list, tuple, set, dictionary

Faculty: Komal Waykole


44
Compare list, tuple, set, dictionary

Faculty: Komal Waykole


45
Type Conversion
 The process of converting the value of one data
type (integer, string, float, etc.) to another data
type is called type conversion. Python has two
types of type conversion.
1. Implicit Type Conversion
2. Explicit Type Conversion

Faculty: Komal Waykole


46
Type Conversion…
 In Implicit type conversion,

 Python automatically converts one data type to


another data type. This process doesn't need any user
involvement.

Faculty: Komal Waykole


47
Type Conversion…
 Explicit Type Conversion,
 users convert the data type of an object to required data
type. We use the predefined functions like int(), float(),
str(), etc to perform explicit type conversion.
 This type of conversion is also called typecasting because
the user casts (changes) the data type of the objects.
 Typecasting can be done by assigning the required data type
function to the expression.

Faculty: Komal Waykole


48
Addition of string and integer using explicit
conversion
 Example:
num_int = 123
num_str = "456"
print("Data type of num_int:",type(num_int))
print("Data type of num_str before Type Casting:",type(num_str))
num_str = int(num_str)
print("Data type of num_str after Type Casting:",type(num_str))
num_sum = num_int + num_str
print("Sum of num_int and num_str:",num_sum)
print("Data type of the sum:",type(num_sum))

Faculty: Komal Waykole


49
Addition of string and integer using explicit
conversion…

 Output:
Data type of num_int: <class 'int'>
Data type of num_str before Type Casting: <class 'str'>
Data type of num_str after Type Casting: <class 'int'>
Sum of num_int and num_str: 579
Data type of the sum: <class 'int'>

Faculty: Komal Waykole


50
Type Conversion…
 Type Conversion is the conversion of object from one data
type to another data type.
 Implicit Type Conversion is automatically performed by
the Python interpreter.
 Python avoids the loss of data in Implicit Type Conversion.
 Explicit Type Conversion is also called Type Casting,
the data types of objects are converted using predefined
functions by the user.
 In Type Casting, loss of data may occur as we enforce the
object to a specific data type.

Faculty: Komal Waykole


51
Python Input, Output and Import

 Python provides numerous built-in functions that are


readily available to us at the Python prompt.

 Some of the functions like input() and print() are


widely used for standard input and output
operations respectively.

Faculty: Komal Waykole


52
Python Output - print() function
 The print() function to output data to the standard output
device (screen).
 syntax of the print() function is:
print(*objects, sep=' ', end='\n', file=sys.stdout,
flush=False)
 Here, objects is the value(s) to be printed.
 The sep separator is used between the values. It defaults into a
space character.
 After all values are printed, end is printed. It defaults into a new
line.
 The file is the object where the values are printed and its default
value is sys.stdout (screen).
Faculty: Komal Waykole
53
Python Output - print() function
example

Faculty: Komal Waykole


54
Python Output formatting
 to format our output to make it look attractive.
 This can be done by using the str.format() method. This
method is visible to any string object.
 x = 5; y = 10
print('The value of x is {} and y is {}'.format(x,y))
 The value of x is 5 and y is 10
 the curly braces {} are used as placeholders. We can
specify the order in which they are printed by using numbers
(tuple index).

Faculty: Komal Waykole


55
Python Output formatting example
 print('I love {0} and {1}'.format('bread','butter'))
 print('I love {1} and {0}'.format('bread','butter‟))
 Output:
 I love bread and butter
 I love butter and bread

Faculty: Komal Waykole


56
Python Input formatting example
 to take the input from the user.
 In Python, we have the input() function to allow this.
 The syntax for input() is:
input([prompt])
 where prompt is the string we wish to display on the screen. It
is optional.
 Example:
num = input('Enter a number: „)
O/P Enter a number: 10
num
O/P '10'

Faculty: Komal Waykole


57
Python Input formatting
example…

 eval() function
 the eval function evaluates the “String” like a python
expression and returns the result as an integer.
 provide the input as a string.
 Syntax:
eval(expression, [globals[, locals]])
 Example: eval('2+3‟)
O/P: 5

Faculty: Komal Waykole


58
Python Import
 When our program grows bigger, it is a good idea to
break it into different modules.
 A module is a file containing Python definitions and
statements.
 Definitions inside a module can be imported to another module
or the interactive interpreter in Python.
 We use the import keyword to do this.
 Example: import math
print(math.pi)
Output:
3.141592653589793

Faculty: Komal Waykole


59
Python Operators (Arthmetic operators)

Faculty: Komal Waykole


60
Floor division operator
 The “//” operator is used to return the closest integer value
which is less than or equal to a specified expression or value.
 Example: Output:
print (5//2) 2
print (-5//2) -3
 5//2 returns 2.You know that 5/2 is 2.5, the closest
integer which is less than or equal is 2[5//2].( it is inverse
to the normal maths, in normal maths the value is 3).

Faculty: Komal Waykole


61
Exponent Operator

 ** operator is used to raise a number in Python to


the power of an exponent. In other words, ** is the
power operator in Python.
 Given two real number operands, one on each side of the
operator, it performs the exponential calculation (2**5 translates
to 2*2*2*2*2).
 Note: Exponent operator ** in Python
works in the same way as the pow(a, b)
function.

Faculty: Komal Waykole


62
Python Operators (Comparison operators)

Faculty: Komal Waykole


63
Python Operators (Logical operators)

Faculty: Komal Waykole


64
Python Operators (Bitwise operators)

Faculty: Komal Waykole


65
Python Operators (Assignment operators)

Faculty: Komal Waykole


66
Python Operators (Assignment operators)…

Faculty: Komal Waykole


67
Python Operators (identity operator)

Faculty: Komal Waykole


68
Python Operators (Special operators)….
Example for Special operators
x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
x3 = [1,2,3] Output
y3 = [1,2,3]

# Output: False False


print(x1 is not y1) True
False
# Output: True
print(x2 is y2)

# Output: False x3 and y3 are lists. They are equal


but not identical. It is because the interpreter locates
them separately in memory although they are equal.
print(x3 is y3)
Faculty: Komal Waykole
69
Python Operators
(Membership operators)
• in and not in are the membership operators in Python. They are used to
test whether a value or variable is found in a sequence (string, list, tuple,
set and dictionary).
• In a dictionary we can only test for presence of key, not the value.

Faculty: Komal Waykole


70
Python Operators
(Membership operators)….
Example for Membership operators
x = 'Hello world'
y = {1:'a',2:'b'} Output

# Output: True True


print('H' in x) True
True
# Output: True False
print('hello' not in x)

# Output: True
print(1 in y)

# Output: False
print('a' in y)

Faculty: Komal Waykole


71
Python Flow Control statements

Faculty: Komal Waykole


72
if... statement

 The if…elif…else statement is used in Python for decision


making.
 Python if Statement Syntax
if test expression:
statement(s)
 Here, the program evaluates the test expression and will
execute statement(s) only if the test expression is True.
 If the test expression is False, the statement(s) is not
executed.

Faculty: Komal Waykole


73
if... statement…

Faculty: Komal Waykole


74
if... statement… Example
EXAMPLE:
a=int(input("enter a no.="))
if a > 0:
print(a," is greater than zero")

OUTPUT:
enter a no.=10
10 is greater than zero

Faculty: Komal Waykole


75
If…else statement
 Syntax of if...else
if test expression:
Body of if
else:
Body of else
 The if..else statement evaluates test expression and will
execute the body of if only when the test condition is
True.
 If the condition is False, the body of else is executed.
Indentation is used to separate the blocks.

Faculty: Komal Waykole


76
If…else statement

Faculty: Komal Waykole


77
if... statement (example)…

a=int(input("enter a no.="))
if a > 0:
print(a," is posti")
else:
print(a," is nega")

OUTPUT:
enter a no.=-2
-2 a= is nega

Faculty: Komal Waykole


78
If…else statement (example)

Faculty: Komal Waykole


79
if...elif...else Statement
 Syntax of if...elif...else
if test expression:
Body of if
elif test expression:
Body of elif
else:
Body of else

 The elif is short for else if. It allows us to check for multiple expressions.
 If the condition for if is False, it checks the condition of the next elif block
and so on.
 If all the conditions are False, the body of else is executed.
 Only one block among the several if...elif...else blocks is executed
according to the condition.
 The if block can have only one else block. But it can have multiple elif
blocks.
Faculty: Komal Waykole
80
if...elif...else Statement flowchart

Faculty: Komal Waykole


81
if...elif...else Statement example

Faculty: Komal Waykole


82
Python Nested if statements

 a if...elif...else statement inside another if...elif...else


statement. This is called nesting in computer
programming.

 Any number of these statements can be nested inside one


another. Indentation is the only way to figure out the
level of nesting.

Faculty: Komal Waykole


83
Python Nested if statements

Faculty: Komal Waykole


84
Indentation
 A code block (body of a function, loop, etc.) starts with
indentation and ends with the first unindented line. The amount
of indentation is up to you, but it must be consistent throughout
that block.
 Generally, four whitespaces are used for indentation and are
preferred over tabs.
 Eg: for i in range(1,11):
print(i)
if i == 5:
break
 The enforcement of indentation in Python makes the code look
neat and clean. This results in Python programs that look similar
and consistent.
Faculty: Komal Waykole
85
Comments
 Comments are very important while writing a program.
They describe what is going on inside a program, so that a
person looking at the source code does not have a hard time
figuring it out.
 Eg: #This is a comment
#print out Hello
print('Hello‟)
 use triple quotes, either ''' or """.
 Eg: """This is also a
perfect example of
multi-line comments"""

Faculty: Komal Waykole


86
While loop in Python
 The while loop in Python is used to iterate over a
block of code as long as the test expression
(condition) is true.
 Syntax of while Loop in Python
while test_expression:
Body of while
 In the while loop, test expression is checked first.
The body of the loop is entered only if
the test_expression evaluates to True. After one
iteration, the test expression is checked again. This
process continues until the test_expression evaluates
to False.
Faculty: Komal Waykole
87
While loop in Python…
 In Python, the body of the while loop is
determined through indentation.
 The body starts with indentation and the first
unindented line marks the end.
 Python interprets any non-zero value as True.
None and 0 are interpreted as False.

Faculty: Komal Waykole


88
While loop in Python…

Faculty: Komal Waykole


89
While loop (sum of n numbers)

Faculty: Komal Waykole


90
While loop with else…
 The else part is executed if the condition in the while loop
evaluates to False.

Faculty: Komal Waykole


91
Program using while loop:

Faculty: Komal Waykole


92
For loop in Python
 The for loop in Python is used to iterate over a
sequence (list, tuple, string) or other iterable
objects. Iterating over a sequence is called traversal.
 Syntax of for Loop
for val in sequence:
loop body
 Here, val is the variable that takes the value of the
item inside the sequence on each iteration.
 Loop continues until we reach the last item in the
sequence. The body of for loop is separated from the
rest of the code using indentation.

Faculty: Komal Waykole


93
For loop Flowchart

Faculty: Komal Waykole


94
For loop Example…
 Program to find the sum of all numbers
stored in a list
# List of numbers
numbers = [6, 5, 3, 8, 4, 2, 5, 4, 11]
# variable to store the sum
sum = 0
# iterate over the list
for val in numbers:
sum = sum+val
print("The sum is", sum)
Faculty: Komal Waykole
95
The range() function
 To generate a sequence of numbers
using range() function.
 Eg: range(10) will generate numbers from 0 to 9
(10 numbers).
 We can also define the start, stop and step size
as range(start, stop,step_size). step_size defaults
to 1 if not provided.
 We can also define the start, stop and step size
as range(start, stop,step_size). step_size defaults to
1 if not provided.

Faculty: Komal Waykole


96
The range() function…
 Operations supported:
in, len and __getitem__ operations.

Faculty: Komal Waykole


97
The range() function…
 We can use the range() function in for loops to
iterate through a sequence of numbers. It can be
combined with the len() function to iterate through
a sequence using indexing.
 # Program to iterate through a list using indexing
genre = ['pop', 'rock', 'jazz']
# iterate over the list using index
for i in range(len(genre)):
print("I like", genre[i])

Faculty: Komal Waykole


98
for loop with else
 A for loop can have an optional else block as well.
The else part is executed if the items in the
sequence used in for loop exhausts.

Faculty: Komal Waykole


99
Program using for loop:

Faculty: Komal Waykole


100
Nested for loop

Faculty: Komal Waykole


101
Pattern
# if you want user to enter a number, uncomment the below line
rows = int(input('Enter the number of rows'))
# outer loop
for i in range(rows):
# nested loop
for j in range(i):
# display number
print(i, end=' ')
# new line after each row
print('')
Faculty: Komal Waykole
102
Pattern…
n=int(input("enter number of rows"))
k=n-1
for i in range(0,n):
for j in range(0,k):
print(end=" ")
k=k-1
for j in range(0,i+1):
print("*",end=" ")
print()
Faculty: Komal Waykole
103
Break and continue statement
 In Python, break and continue statements can
alter the flow of a normal loop.
 Loops iterate over a block of code until the
test expression is false, but sometimes we wish
to terminate the current iteration or even the
whole loop without checking test expression.
 The break and continue statements are used
in these cases.

Faculty: Komal Waykole


104
Break statement
 The break statement terminates the loop containing
it. Control of the program flows to the statement
immediately after the body of the loop.
 If the break statement is inside a nested loop (loop
inside another loop), the break statement will
terminate the innermost loop.
 Syntax of break
break

Faculty: Komal Waykole


105
Break statement….

Faculty: Komal Waykole


106
Break statement working….

Faculty: Komal Waykole


107
Break statement example….

Faculty: Komal Waykole


108
Continue statement
 The continue statement is used to skip the rest of
the code inside a loop for the current iteration only.
Loop does not terminate but continues on with the
next iteration.
 Syntax of Continue
continue

Faculty: Komal Waykole


109
Continue statement…

Faculty: Komal Waykole


110
Continue statement…

Faculty: Komal Waykole


111
Continue statement Example…

Faculty: Komal Waykole


112
Pass statement
 the pass keyword is used to execute nothing; it means, when
we don't want to execute code, the pass can be used to
execute empty.
 It just makes the control to pass by without executing any
code. If we want to bypass any code, pass statement can be
used.
 It is beneficial when a statement is required syntactically, but
we don't want to execute or execute it later.
 The difference between the comments and pass is that,
comments are entirely ignored by the Python interpreter,
where the pass statement is not ignored.

Faculty: Komal Waykole


113
Pass statement Example…

Faculty: Komal Waykole


114
Important questions
1. features of python?
2. difference between c and python?
3. define:
1. keywords,
2. variable,
3. constant,
4. identifier,
5. tuple,
6. list,
7. sets,
8. string,
9. dictionary,
10. type conversion
4. compare: list, set ,tuple ,dictionary
5. explain type casting or explicit conversion
6. explain input and output statements in python
7. explain membership operator
8. explain Identity operator

Faculty: Komal Waykole


115
Important questions
1. what is range function? give suitable example
2. write short note break statement
3. write short note continue statement
4. write short note Pass statement
5. What is interpreter?
6. How python program is executed using interpreter? Give
example
7. Difference between == and is operator?
8. Explain slicing operator and indexing w.r.t LIST
9. What are mutable and immutable datatypes? give example
10. Explain sequence datatypes with example?
11. Explain the difference between variable w.r.t C ad python
Faculty: Komal Waykole
116
Important questions
1. write short note on if...elif...else statement
2. explain while loop with example
3. explain for loop with example
4. Justify “list is mutable". Give suitable example
5. What are python built-in datatypes

Faculty: Komal Waykole


117

You might also like