All Courses
Advanced Python

Advanced Python

May 20th, 2019 python

Python Advanced topics

The  Advance Python concepts contain the following topics as follows

  • Python Iterator
  • Python Generator
  • Python Property
  • Python Decorators

Python Iterator:

             The Iterator Object has formally two methods to traverse to all values. This is called as python Iterator.

 Methods:

  • ___iter__()
  • __next__()
 Example  1:  Iterator Values in array
mylist=("a","b","c")
mylis=iter(mylist)
print(next(mylis))
print(next(mylis))
print(next(mylis))
 Example  2: Iterator Values in string
value="Chennai"
city=iter(value)
print(next(city))
print(next(city))
print(next(city))
print(next(city))
print(next(city))
print(next(city))
print(next(city))
print(next(city))
 Example  3: Iterator in loops
value="Chennai"
for k in value:
print(k)

Python Generator :

    The python Generator uses the keyword yield. The Generator function consists of two types

  • Generator function
  • Genrator Object

 Generator Function:

It is a normal function with a statement to return a value, if the function contains one yield statement then it is called as Generator Function.

 Example:
def fun():
yield 1
yield 2
yield 3
for value in fun():
print(value)

Generator Object:

The Generator Function Returns the generator Object with the use of the next statement is being called in the statement.

 Example:
 def fun():
  yield 1
  yield 2
  yield 3
  x=fun()
 print(x.next())
 print(x.next())
 print(x.next())

Python Property :

The python property is the concepts that make them easier. These built-in decorators. The python Property is one of the hte decorators let us see an example using python property.

Example:
Class student:
def __init__(name,mark):
self.name=name
self.mark=mark
@property
def gotmark()
return  self.name + self.mark
@property   ##gotmarks.setter
def gotmark(self,kk)
nam,rand,marks=kk.split(' ')
self.name=name
self.mark=mark
s1=student(''abc","54")
print(s1.name)
printI(s1.mark)
print(s1.gotmarks)
s1.gotmarks(''abc got 45 '')
print(s1.name)
printI(s1.mark)
print(s1.gotmarks)
 

Python  Decorators:

This  allows make simple modifications to callable objects like functions,methods and class.

 Example1:
@decorator
def fun(args):
return value
fun1=decorator_func(fun)
print(fun1)
  Example 2:
@decorator_ upper_case
def wraper(value):
value=function()
upper_case=value . upper()
return  upper_case            
fun1=decorator_ upper_case(value)
print(fun1)
Social Share:

0 responses on "Advanced Python"

Leave a Message

Your email address will not be published. Required fields are marked *