Python Basic and Advanced-Day 4
Python Basic and Advanced-Day 4
1 Python Basics
o Python – Overview
2 Python Advanced
o Python - Classes/Objects
o Python - Environment Setup
Content
o Python - Basic Syntax o Python - Reg Expressions
a) ‘first=H, third=L’
b) ‘first=0, third=2’
c) Error
d) ‘first=0, third=L’
Python Basics
Quiz
a) ‘first=H, third=L’
b) ‘first=0, third=2’
c) Error
d) ‘first=0, third=L’
o List
o Dictionary
o Tuple
o Array
Python Basics
Quiz
o List
o Dictionary
o Tuple
o Array
a) 01230
b) 0120
c) 012
d) Error
Python Basics
Quiz
a) 01230
b) 0120
c) 012
d) Error
>>>"a"+"bc"
a) a
b) bc
c) bca
d) abc
Python Basics
Quiz
>>>"a"+"bc"
a) a
b) bc
c) bca
d) abc
var = 10
while var > 0:
2 continue statement Causes the loop to print('Current variable value :', var)
skip the remainder of its body and var = var -1
immediately retest its condition prior to if var == 5:
reiterating. break
print("Good bye!")
var = 10
while var > 0:
var = var -1
if var == 5:
continue
print('Current variable value :', var)
print("Good bye!")
Python Basics
Loop Control Statement- Pass
It is used when a statement is required syntactically but you do not want any command or code to execute.
Example Output
for letter in 'Python':
if letter == 'h':
pass
print('This is pass block’)
print('Current Letter :', letter)
This function yields a sequence of numbers. When called with one argument, say n, it creates a sequence of numbers
from 0 to n-1.
print(list(range(10)))
print(list(range(2,7)))
print(list(range(2,12,2)))
print(list(range(12,2,-2)))
Python Basics
Function
A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity
for your application and a high degree of code reusing.
Python gives you many built-in functions like print(), etc. but you can also create your own functions. These functions are
called user-defined functions.
These functions are called anonymous because they are not declared in the standard manner by using
the def keyword. You can use the lambda keyword to create small anonymous functions.
Syntax Output
lambda [arg1 [,arg2,.....argn]]:expression
Example
# Function definition is here
sum = lambda arg1, arg2: arg1 + arg2;
All variables in a program may not be accessible at all locations in that program. This depends on where you have
declared a variable.
• Global variables
• Local variables
Variables that are defined inside a function body have a local scope, and those defined outside have a global scope.
Example:
total = 0; # This is global variable. Output
# Function definition is here
def sum( arg1, arg2 ):
# Add both the parameters and return them."
total = arg1 + arg2; # Here total is local variable.
print("Inside the function local total : ", total)
return total;
A library for Python, NumPy lets you work with huge, multidimensional matrices and arrays. Along with that, it
provides a mechanism of high-level functions to perform mathematical operations on these structures
Feature
o Multidimensional arrays.
o Functions and operators for these arrays.
o ndarray- n-dimensional arrays.
o Fourier transforms and shapes manipulation.
o Linear algebra and random number generation.
Thank you