Professional Documents
Culture Documents
Python Training: Core & Advanced
Python Training: Core & Advanced
Simple-Syntax
Fast-inbuild Libraries
why
Easy to Learn/Use
Performance
Rapid Development
Dynamically Typed
Community
It consists of Third party libraries such as cherrypy and botto and many more
Software setup
Install python
Multiline comment
Data types
Int
Float
String
Five Different ways
None Type
Numeric Type
Sequences
Sets
Mappings
Numeric type
Int
Float
Complex
Using J
Binary :0B1010
HexaDecimal:0xff
Boolean
Typecasting
Sequences
• Collections
List
Set
Dictionary
Strings In-depth
current position of index
Repetition
print 0 to 5
• lStrip()
• rStrip()
Some more methods for Strings
Find
Count
Replace
Upper
Lower
title
List
it is implemented to store the sequence of various type of data.
A list can be defined as a collection of values or items of
different types.
The items in the list are separated with the comma (,) and
enclosed with the square brackets [].
The indexing are processed in the same way as it happens with
the strings.
The elements of the list can be accessed by using the slice
operator [].
List
Show List
Index
Repetition
Append
Remove
Delete >>del>>default delete by using del() method by calling index>>del(list[2])
Clear()
Max(list)
Min(list)
Insert()
Sort()
Sort(reverse=true)
Tuple
It always start with ()
Tuple is used to store the sequence of immutable python
objects.
value of the items stored in the list can be changed
the tuple is immutable and the value of the items stored
in the tuple can not be changed.
suppose we try to reassign the items of a tuple, we
would get an error as the tuple object doesn't support
the item assignment.
Tuple()
A tuple starts with a normal bracket and it ends with a normal bracket
as well.
It cannot be modified
Append()
Extend()
Insert()
Remove()
Clear()
We cannot use these all methods
Work with
index
repetition
count
tpl=(10,)
Remove()
Frozenset(set)
Range type
• Range(value)
• Range(Fvalue,Lvalue)
• Range(Fvalue,Lvalue,JumpingValue)
Bytes & ByteArray
• bytes(list) >>once converted check only type,and cannot change
• C.items
• C.keys
• C.values
• Index
• Del c[2]
Operators and Operands
• Arithmetic Operators
•+
•-
•/
•*
•%
• ** power
• // Floor
Assignment Operators
•=
• += //compound assignment
• -=
• *=
• /=
• %=
• **=
• //=
Comparison Operators
• ==
• !=
•>
•<
• <=
• >=
Logical Operators
• X and y = true(both should be true)
• X and y =true(any one true)
• Not x =true(it wil make it false)
• Sep=‘++’
• name='sandy'
• f=10.25
• print("my name is",name,"and",f)
• print("my name is %s and %f"%(name,f))
• print("my name is {} and {}".format(name,f))
• print("my name is {0} and {1}".format(name,f))
Input and Output Functions
• Input()
• String way
• Integer way with type
• Using[int(x) for x in input().split() ]
Problem solvings
• Student details
• Id
• Name
• Marks
• Looping
• While
• For
• Transfer
• Break,continue
• Pass,return
• Find even and odd using if else
• If else ladder using if..elif..else
• While loop
• Show even or odd numbers to print using min and max.
• Using loop print 30 to 50.
• Using loop print 5 to 50 and jump 5.
• List of numbers all should be multiplied.
• d Multiplication table for given value.
• Using break
• Using Continue //jump
• Assert
Command Line Arguments
Command Line Arguments
Display the command line arguments with index.
Script/program Name>>int(l[1])*int(l[2])
Functions
Functions are the most important aspect of an application.
A function can be defined as the organized block of reusable code
which can be called whenever required.
Python allows us to divide a large program into the basic building
blocks known as function.
The function contains the set of programming statements enclosed by
{}
A function can be called multiple times to provide reusability and
modularity to the python program.
By using functions, we can avoid rewriting same logic/code again and
again in a program.
• Average value of 2 numbers
• Using return.
• Arithmetic Operations using function
• Local and Global Variable
• Assign functions to variable
• Function inside another function.
• Returning a function
• Pass any type
• Factorial
lambdas
• The anonymous functions are declared by using lambda keyword.
• Lambda functions can accept any number of arguments, but they can return only
one value in the form of expression.
• The lambda function can be used as an argument to the higher order functions
as arguments.
Filters,Map,Reduce
Filters
filter() function is used to get filtered elements.
This function takes two arguments, first is a function and the second is iterable.
The filter function returns a sequence from those elements of iterable for which
function returns True.
list(filter(lambda x:x%2==0,l))
• Map
The map() function in Python takes in a function and a list as argument.
The function is called with a lambda function and a list and a new list is returned
which contains all the lambda modified items returned by that function for each
item.
list(map(lambda x:x*2,l))
Reduce
This is a part of functools module
It takes in a function and a list as argument.
The function is called with a lambda function and a list and a new reduced result
is returned.
Lambdas
Lambdas simple
Lambdas addition
Lambdas Multiplication
Create a Lambda that will calculate the cube of a given Number
Create a Lambda that will return yes if the given number is even else and no if it
it odd
Retrive only even numbers from a given list using filters
using the map function double the value of each element in the list
Using reduce fuction add all the numbers
Decorators
• A decorator is a design pattern that allows a user to add new functionality to an
existing object without modifying its structure.
• Decorators are usually called before the definition of a function you want to
decorate.
• Create 2 different function with print
• Create a outer and inner function and with separate function and print
• Using @decor
• Using @decor ,use outer inner function with separate function show the strings
linking with functions.
Generators
• A generator function is defined like a normal function, but whenever it needs to
generate a value, it does so with the yield keyword rather than return.
• If the body of a def contains yield, the function automatically becomes a
generator function.
• Yield can produce a sequence of values.
• customerGen using x and y,while and yield will be stored in memory by using
loop
• Create a mymath module and use it. And use it in another script.
• Diff ways to import
• >calling as alies
• >calling as *
List comprehensions
• list comprehensions are a shortcut to create one list out of another by applying
the logic we want
• on the first list as well as we can also apply conditions on the right hand side only
if the condition
• is satisfied that item will be included in the resulting list.
• And this logic will be applied to each and every item in the list.
• Cube of numbers in a list using range of 10.
• Even numbers between 1 to 100 jump by 2 by if condition
• Products of numbers in list(2 arrays multiply).
• Common elements of two lists.