How To Use Functions In Python (Python Tutorial #3)

This entire series in a playlist: https://goo.gl/eVauVX
Keep in touch on Facebook: https://www.facebook.com/entercsdojo
Subscribe to my newsletter: https://www.csdojo.io/news
Support me on Patreon: https://www.patreon.com/csdojo

Tips:
1. Follow along as I explain to make sure you understand everything
2. Ideally, work with a friend so you can help each other when you’re stuck
3. If you want to learn faster than I talk, I’d recommend 1.25x or 1.5x speed :)
4. Check the outline in the comment section below if you want to skip around.
5. Download the sample files here to follow along (they are Jupyter Notebook files): https://www.csdojo.io/python3
6. To make sure you don’t miss my future tutorial videos, sign up to my newsletter: https://www.csdojo.io/news
7. Have fun! If anything is unclear, please let me know in a comment.

Keep in touch on Facebook: https://www.facebook.com/entercsdojo
Subscribe to my newsletter: https://www.csdojo.io/news
Support me on Patreon: https://www.patreon.com/csdojo

Comments

Sagn C says:

I am not clear about that 4 space that you leave everytime.

Liu Michael says:

Probably

24/8 says:

i started to love programming and i started just like today

Wisdom Tainamei says:

Hi brother/sir CS Dojo, appreciate what ur doing. M learning python through ur channel m sure its the best of best n m new to tech and m from commerce background. BY the way i have a small request, if at all you have time pls make a video on how to install microsoft apps to ubuntu, (eg: power bi) and also pls run me through the important keys in libre office (excel) necessary for data science. ( eg: pivot and options used to to analyse and visualise data ) Many thanks. God bless.

kazoozleable says:

Hi YK! This might seem really stupid, but why cant i add “?” in my What are functions title like you can? it gives me the following error message: Unknown error renaming file: Desktop/Python Tutorial 3/What are functions.ipynb [Errno 22] Invalid argument: ‘C:\Users\Diana\Desktop\Python Tutorial 3\What are functions?.ipynb’

I know I could probably just name it without the ?, but I just was curious to know why. Thanks!

Jane Ekegbu says:

Return function starts 5:05

siddhant mane says:

Hey,Cs dojo please start tutorials of JavaScript

imran farooq beigh says:

Great I never understood functions and you made it easy god bless

ManofSteele25 says:

dude i appreciate the efort you go through to make these videos, and becuz of it i have a better understanding of “what” python is, but every single tutorial pretty much just talks about python but we dont put any of it to use, come up with some small working programs or applications and lets build it together! , line by line step by step, discussing why we use this function or that value and how it effects the program we r trying to build

CS Dojo says:

Below is an outline of this video.
0:41: How to use sample files
1:41: Using comments
2:21: What’s a function? – Example 1
4:57: What’s a function? – Example 2
7:09: A function that takes multiple arguments
7:58: What’s a function? – 2 more examples
10:30: Creating a BMI calculator

Also, a few tips:
1. Here is the playlist for this series: https://www.youtube.com/watch?v=Z1Yd7upQsXY&list=PLBZBJbE_rGRWeh5mIBhD-hhDwSEDxogDg
2. Follow along as I explain to make sure you understand everything
3. Ideally, work with a friend so you can help each other when you’re stuck
4. If you want to learn faster than I talk, I’d recommend 1.25x or 1.5x speed :)
5. Check the outline in the comment section below if you want to skip around.
6. Download the sample files here to follow along (they are Jupyter Notebook files): https://www.csdojo.io/python3
7. To make sure you don’t miss my future tutorial videos, sign up to my newsletter: https://www.csdojo.io/news
8. Have fun! If anything is unclear, please let me know in a comment.

Silent Slumber says:

i have made my own function with what i learn from your video,
def function2(x, y, z)
print(x, y, z)
print(“hi”)
return 4*x, 4*y, 4*z
a = function2(x, y, z)
print(a)

Supergrupo TEIT says:

Hey, I’m trying to make a function that swaps 2 variables. (this is it):
def swap(a,b):
temp=a
a=b
b=temp
print(a,b)
return b,a

a=1
b=2
swap(a,b)
print(a,b)
the console prints 2,1 because of the function, so the swap is ok. But then it prints 1,2. what can i do?

Drako Gemini says:

Thanks CS Dojo

ravencraft says:

I tried writing it ahead of you just to compare results, I was pretty close – I wonder if this is something acceptable (printing the result instead of returning it)

# BMI Calculator

person_1 = “Vlad”
weight_kg_person_1 = 77
height_m_person_1 = 1.8

person_2 = “James”
weight_kg_person_2 = 63
height_m_person_2 = 1.65

person_3 = “Kevin”
weight_kg_person_3 = 94
height_m_person_3 = 1.61

def bmi_calculator(name, weight_kg, height_m):
bmi = weight_kg / (height_m ** 2)
print (name, “has a weight of”, weight_kg, “kilograms and a height of”, height_m, “meters.”)
print(“The BMI score for”, name, “is”, bmi)
if bmi < 25: print(name, “is not overweight.”) else: print(name, “is overweight.”) bmi_calculator(person_1, weight_kg_person_1, height_m_person_1) bmi_calculator(person_2, weight_kg_person_2, height_m_person_2) bmi_calculator(person_3, weight_kg_person_3, height_m_person_3) Prints: Vlad has a weight of 77 kilograms and a height of 1.8 meters. The BMI score for Vlad is 23.76543209876543 Vlad is not overweight. James has a weight of 63 kilograms and a height of 1.65 meters. The BMI score for James is 23.140495867768596 James is not overweight. Kevin has a weight of 94 kilograms and a height of 1.61 meters. The BMI score for Kevin is 36.264033023417305 Kevin is overweight.

Zeeshan Rayyan says:

Sir iam new and begginner student of python… as you have created amazing tutorials, create some on how to use python in a website as well as in any app…
thanks a lot

xXGH0STXx - says:

Do you have to use kg and meters??

Kaylee says:

why in the code when you had the print(“this is outside the function”) as the last line of code it didn’t print after the called function.

no function called…
this is out of the function

yet when the function is called it ignores the rest of the code ??

sorry im sure this is stupid to ask but I am genuinely trying to learn.

Tristian De Jong says:

a =(float(input(“Enter your height in metres: “)))
b =(float(input(“Enter your weight in kilogram: “)))

c = b/a**2

print(“Your Body Mass Index is :” ,c)

Texturiser says:

Here is my answer for the final exercise:

def convert(miles):
print(miles, ‘miles = ‘)
return 1.6 * miles

print (convert(3))

And the output is:

1 miles =
1.6

ragav vignesh says:

Thanks bro

Ivan Sakal says:

yk i have 1 question
so when i’m defining variables and functions, should i first define funcitons or variables?

Denise Cherdak says:

What happens if you have two return commands in a single function? does it only stop at the first one or does it execute both return functions?

imran farooq beigh says:

hi your class related to python are awesome and I learnt a lot thanks a lot, can you plz make a video how to run python and juipter notebook on windows 10, I installed it but it is not running Juipter notebook pLZ PLZ PLZ

Sehun Han says:

Hello YK. I was trying to rename my new notebook for this turtorial to “What are functions?” without the quotation marks.
I got this error message:
Unknown error renaming file: Desktop/Python Learning/What are functions.ipynb [Errno 22] Invalid argument: ‘C:\Users\User\Desktop\Python Learning\What are functions?.ipynb’

I tried with other names such as Untitled 1, etc and it worked, but it wouldn’t work with “What are functions?”
Why does this happen?

Kireeti Kittu says:

What is def

Manogna Ogety says:

I have doubt while I am typing function program inside the function I am giving the print statement but while I am giving print statement outside the function it’s showing error can anyone please clear my doubt

Number Cruncher says:

Thank you for this helpful video!

WhiteTiger Patil says:

miles=50
def function(x):
print(x)
print(‘the above value is in miles’)
return x*1.6
f=function(miles)
print(f)
print(“the above value is now in kms”)
i made my own mile to km calc is it nice?
can i get your email so i can personally chat with you ?
i am a big fan of you yk
please email me if you liked my program at shashviru@gmail.com and please send your email id.

Yuting Liu says:

really good tutorial for learning python

Rajju Angare says:

Can you tell how to get your code

Shalini Sivakumar says:

can u put many problems based on functions,so that I could understand Functions concept clearly

Aman Pandey says:

Nice

Nic Fisher says:

yes!!! I got it had to rewrite result1(name1, height_m1, weight_kg1)
and it worked it defined name like it was supposed to. thanks everyone for the help.

Mikhail Kuchukhidze says:

I’m so glad you’re using the INTERNATIONAL METRIC SYSTEM

Adventure Gamer says:

i would like you to make regular calculator no bmi calculator

Karthikeya Ch says:

Sir, please do a data structures & memory management video

Shalini Sivakumar says:

can u write the python programme to swap two numbers using functions

sagar p says:

can i use python to build apps like facebook and instagram ?? please answer me

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours