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



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

MONDAY EXERCISES


  1. Print Name: Define a function called myName, and have it print out your name when called.

  2. Pizza Toppings: Define a function that prints out all your favorite pizza toppings called pizzaToppings. Call the function three times.


although there wasn’t much coding today, it was important to understand the value of functions. now we can separate our code into blocks, which will make the program easier to read and run.
Parameters'>Tuesday: Parameters
One of the main reasons we use functions is so that we can make our code modular. Today is all about understanding how to use parameters within functions and what they are.
To follow along with this lesson, let’s continue from our previous notebook file “Week_05” and simply add a markdown cell at the bottom that says, “Parameters.”
What Are Parameters?
Parameters are temporary variables declared on the function definition. While the functions we’ve written so far perform a specific task, they aren’t modular because they will always print out the same response for every call. When you want to call a function with different values, you need to use parameters. Within the parenthesis of the function definition is where you would state a parameter name. This is an arbitrary variable name that you use to reference the value within the function block; however, you usually want it to be relevant to the data that you’re working with. When calling the function, you would pass in the necessary value to run the block of code with. Take Figure 5-3.

Figure 5-3. Accepting parameters into a function
CHapTeR 5 FUnCTIonS
Note arguments are the values passed into the function call. In the preceding figure, line 3 is passing the argument “John” into the printname function, where it will the value will be passed into the parameter name
The function is defined with a parameter of “name” within the parenthesis. Again, this could be called anything, but we’re expecting a person’s name to be passed in. The block of code, when executed, will use the value of that parameter within the formatted print statement. The call on line 3 is where we pass the value into the function, known as an argument. In this example, we would get an output of “Hello John”. We could can now call this function and pass in any string value we would like, and it will print it out. This function is now modular.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   77   78   79   80   81   82   83   84   ...   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