How to Make (Define) a Function in Python

preview_player
Показать описание
This video shows the basics of making and calling functions in Python and supplying functions with default arguments. Code available in the pinned comment below!
Рекомендации по теме
Комментарии
Автор

# Define functions with def

def function_name(function_argument_1, function_argument_2):

# Function body
multiplied = function_argument_1 * function_argument_2

# Return value - What comes out of the function
return multiplied

# Call the function on some inputs after it has been defined:

function_name(5, 10)

# Set a default function argument value with =

def combine_strings(word1 = "Hello", word2 = "World", sep = " "):

return word1 + sep + word2



combine_strings()

combine_strings("Data", "Daft", sep = "")

# Use the output of one function call as input to another:

combine_strings(combine_strings("Data", "Daft", sep = ""), "Rules!")

DataDaft
Автор

That was extremely helpful, I'm currently studying IT and was stuck with this in the textbook, this makes more sense I'll subscribe to your channel as your explanation was well structured.

scottcuthbert
Автор

Please make a video on yield I don't understand how it works, would really appreciate it

ryanmanchikanti
Автор

Great explanation, made it much easier to understand!

worriedaim
Автор

thanks. I didn't need a guy to read the pages for me tho. I was expecting you would show "how to make a function" instead of reading this document.

darth
Автор

Thank you very much this video helped me. i'll come back to this comment when i get accepted into WTC

nontheyet
Автор

hi, im new to python, i want to calculate ittrative calculation, using def function..do u have any related video relateed to that

sujith
Автор

for hello world isn't it easier to just use print ('Hello, World!') ? why use a function to do this?

Superstar-nltl