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



Download 2,61 Mb.
bet84/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   80   81   82   83   84   85   86   87   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

** kwargs


Like args, kwargs allows us to take in an arbitrary number of values in a function; however, it works as a dictionary with keyword arguments instead. Keyword arguments are values passed in with keys, which allow us to access them easily within the function block. Again, the magic here is in the two unary operators (**) not the keyword of kwargs. Let’s check it out:

# using kwargs parameter to take in a dictionary of arbitrary values def outputData(**kwargs): print( type(kwargs) ) print( kwargs[ "name" ] ) print( kwargs[ "num" ] ) outputData(name = "John Smith", num = 5, b = True)

Go ahead and run the cell. This time we can see that the type is a dictionary and we’re able to output each key-value pair within the kwargs parameter like we would with any other dictionary. The keyword arguments within this cell are in the function call, where we specifically declare a key and value to be passed into the function.

CHapTeR 5

FUnCTIonS

TUESDAY EXERCISES


  1. User Input: ask the user to input a word, and pass that word into a function that checks if the word starts with an uppercase. If it does output “True”, otherwise “False”.

  2. No Name: Define a function that takes in two arguments, first_name and last_ name, and makes both optional. If no values are passed into the parameters, it should output “No name passed in”; otherwise, it should print out the name.


Today was all about function parameters and how to use them. The use of parameters makes our functions modular within our program, so that we can successfully reduce the lines of code written.
Wednesday: Return Statement
Up to this point, we’ve been printing out the data that our functions alter, but what do you do if you need to access this information later? This is where the return statement is used. Functions can manipulate data and then send it back to where the function call occurred to save the information to be used for later. Today we’ll learn how to do that and why it’s useful.
To follow along with this lesson, let’s continue from our notebook file “Week_05” and simply add a markdown cell at the bottom that says, “Return Statement.”

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   80   81   82   83   84   85   86   87   ...   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