Python Projects for Beginners a ten-Week Bootcamp Approach to Python Programming



Download 2,61 Mb.
bet154/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   150   151   152   153   154   155   156   157   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

MONDAY EXERCISES


  1. . Reverse Iteration: Create an iterator that takes in a list, and when iterated over, it returns the information in a reverse order. Hint: When accepting arguments into an iterator, you need to use the init method, as well as iter and next. the following call should result in “5, 4, 3, 2, 1”.

>>> for i in RevIter( [ 1, 2, 3, 4, 5 ] ):

  1. . Squares: Create a generator that acts like the range function, except it yields a squared number every time. the result of the following call should be “0, 1, 4, 16”.

>>> for i in range(4):

today we were able to understand how to build our own range function, as well as how data collections can be iterated over. Generators are simplified version of iterators but use the yield keyword to return information. iterators must always be created by using the iter and next methods and are useful for creating our own sequence for iterating.
Tuesday: Decorators
If you want to learn about frameworks, or understand how to improve functions within Python, then you need to understand what a decorator is and how it works. It will help to simplify our code as well as reduce the lines necessary to improve our programs.
To follow along with this lesson, let’s continue from our previous notebook file
Week_09” and simply add a markdown cell at the bottom that says “Decorators.
What Are Decorators?
Decorators, also known as wrappers, are functions that give other functions extra capabilities without explicitly modifying them. They are denoted by the “@” symbol in front of the function name, which is written above a function declaration like the
following:
>>> @decorator >>> def normalFunc( ):
Decorators are useful when you want to perform some functionality before or after a function executes. For example, let’s imagine you wanted to restrict access to a function based on a user being logged in. Rather than writing the same conditional statement for every function you create, you could put the code into a decorator and apply the decorator onto all functions. Now, whenever a function is called, the conditional statement will still run, but you were able to save yourself several lines. This is a real-life example for the Flask framework, which restricts access to certain pages based on user authentication using decorators. We’ll see a minimal example of this later today.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   150   151   152   153   154   155   156   157   ...   200




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish