## Python Tutorial for Beginners 8: Functions

In this Python Beginner Tutorial, we will begin learning how to write functions. Functions are one of the most important things to learn in Python Programming and will take us to the next level. We will learn how to create/define functions, how to pass in arguments, and also how to return values. Let’s get started.

The code from this video can be found at:
https://github.com/CoreyMSchafer/code_snippets/tree/master/Python-Functions

Watch the full Python Beginner Series here:

Scope Video: https://youtu.be/QVdf0LgmICw

If you enjoy these videos and would like to support my channel, I would greatly appreciate any assistance through my Patreon account:
https://www.patreon.com/coreyms

Or a one-time contribution through PayPal:
https://goo.gl/649HFY

If you would like to see additional ways in which you can support the channel, you can check out my support page:
http://coreyms.com/support/

Equipment I use and books I recommend:
https://www.amazon.com/shop/coreyschafer

You can find me on:
My website – http://coreyms.com/
Instagram – https://www.instagram.com/coreymschafer/

#Python

• Views:268,246 views
• Rating:
• Categories:
• Tags:

Saleh Saeed says:

It is great courses here, Thank you so much Corey
one question here, I didn’t get why use ‘and’ condition with (year % 100 != 1 or year % 400 == 0) , I think (year % 4 ==0) is enough I tried first condition with many years and working good.

Meow8404 says:

14:10 Who else noticed a slight change in his voice?

Saleh Saeed says:

It is great courses here, Thank you so much Corey
one question here, I didn’t get why use ‘and’ condition with (year % 100 != 1 or year % 400 == 0) , I think (year % 4 ==0) is enough I tried first condition with many years and working good.

No doubt awesome video! But, does this mean I don’t have to use main() to execute my functions in a program?

stretch654 says:

I must admit Python is pretty darn elegant. It does so much in so few lines.

Lowprojects says:

ugh. so confusing

The Nerdy Anarchist says:

TIL that not every century turn is a leap year. I did not know that….had to look it up to prove myself wrong.

Satheesh kumar says:

Awesome explanations

Maurice Williams says:

The word def in Python means define not definition even thought it’s pretty much the same thing.

pecanpie9 says:

Is there a video on sorting algorithms?

Venera Nurdinova says:

Is there an option that we can do like “def function_name(*args,**kwargs,**kwargs)” to pass more variables? Thanks

Nazar Tymoshchuk says:

Hey Corey!
Thanks a lot for your videos! I’m bit confused with the use of parentheses ( ), brackets [ ] and curly braces { }.
In this video, you use curly braces { } to pass arguments into the function for example. But from an earlier video, you told they are used for Sets and Dictionaries.
In other cases, brackets [ ] are being used.
Overall it is not intuitive what to use (parentheses ( ), brackets [ ] or curly braces { } ) in diferent cases.

Sheriff S says:

Very comprehensive. So GET Rest Api basically runs functions, hope you have tutorial on that too.

Mir says:

These videos are too good. Python official tutorial is very confusing, it advanced BS example which are non sense.

john kilian says:

whst ide are you using?

GreenDemon125 says:

Crisp, solid and well paced explanations. These videos are a godsend, thank you for making these.

! You teach in style!!. Thanks great man!

vijay singh says:

Good explanation. Thanks
https://goo.gl/PsqQhk

Yash Pal Goyal says:

0:27 absolutely thoughtless font size and recording setting u are working with. Why so much empty screen……. !!!!!????

Everything else was fine.

hisam david says:

Can i know the editor name?plz

Karthick Raju says:

Instantly subbed after watching one of your videos. This is the best Puthon channel I’ve seen. Keep up your Great work

ANDY STEPHEN DEJUMO says:

print(” Karenderya”)
print(“Menu: n 1.) Breakfast (Combo Meal) n 2.) Lunch (Combo Meal) n 3.) Drinks n 4.) Dessert”)
“1” :”Breakfast”,
“2” :”Lunch”,
“3” :”Drinks”,
“4” :”Dessert”
}
choice = input(“Enter your category 1:”)

while True:

if choice == “1”:
print(” A1.) Tapsilog – P60 n A2.)Longsilog – P50 n A3.)Hotsilog – P45″)
elif choice == “2”:
print(” B1.)Pakbet w/ rice – P35 n B2.)Sinigang na Baboy w/ rice – P50n B3.)Nilagang Baboy w/ rice – P50″)
elif choice == “3”:
print(” C1.)Iced Tea – P20 n C2.) Botteled Water – P12n C3.)Soda – P25″)
elif choice == “4”:
print(” D1.)Brownies – 25 n D2.) Butterscotch – P25 n D3.) Turon – P10″)
break

while True:
if choice_a == “A1″:
print (” Tapsilog – P 60′”)
elif choice_a == “A2″:
print(” Longsilog – P 50″)
elif choice_a == “A3″:
print(” Hotsilog – P 45″)

#===========================================
if choice_a == “B1″:
print (” Pakbet w/rice – P35″)
elif choice_a == “B2″:
print(” Sinigang na baboy w/ rice – P50″)
elif choice_a == “B3″:
print(” Nilagang Baboy w/ rice – P50″)
#===========================================
if choice_a == “C1″:
print (” Iced Tea – P20″)
elif choice_a == “C2″:
print(” Botteled Water – P12″)
elif choice_a == “C3″:
print(” Soda – P25″)
#============================================
if choice_a == “D1″:
print (” Brownies – P25″)
elif choice_a == “D2″:
print(” Butterscotch-P25″)
elif choice_a == “D3″:
print(” Turon- P10″)
else:
print()
break
print(” To compute the price:”)
print()
price = int(input(“Enter the price:”))
pcs = int(input(“How Many Pieces? :”))
t_price = price*pcs
print(“Total Price:” , t_price)

print(” To compute the change:”)
print()
customer_money=int(input(“Enter the money of your customer: “))

print(“Change:”, customer_money – t_price)

print(“Thank you for your order :-)”)

How can i input the function for this?

Pace De La Cruz says:

Appreciate the content, thank you but way too small on an iphone

jks Saha says:

a=int(input(‘enter a no’))
print (a)

It’s giving an error…that invalid literal for int() with base 10: ‘ ‘

Dibben Nandakishor says:

Hi, I am new to pyhton, just wandering when when do u ues () and []?

SHRIKANTH Y says:

Thank you and pretty good

basirr payenda says:

Thank you sir

hi, Sir i have a question . i write this simple code in python idle but when i write and run in sublime it executed . will you pls explain the reason , here i the code.
def cals():
a=12
b=2
return(a*b)

print(cals())

majidalig says:

Thanks for the excellent tutorial.

Found some useful information here as well for someone who might be interested.
https://treyhunner.com/2018/04/keyword-arguments-in-python/

Deepak Iyer says:

Myles Gmail says:

I tweeted this, TY for these videos

m0neez says:

00:00 def intro
07:00 passing arguments
10:27 args & kwargs
15:01 example

Samir Noori says:

too complicated!!! make it simple!

muffinspuffinsEE says:

SUBBD, BELLD FAPP- oh nvm too much

Best Hindi Tutorials says:

What’s interesting about Python functions is that in Python function body’s are treated as values and stored in local symbol table. That value (function-body) can be applied to another name (function-name) and then that name (function) will act same as previous function. Just like variables.

ahmed abdirahman haji says:

Thanks.

CubisticDog says:

doing computing GCSE and your videos have really helped me – thanks bro 🙂

johnny onthespot says:

I love that your videos are FAST paced, CLEAR with no idle chatter and with QUICK examples that show every aspect of what you are teaching. Of all the Python tutorials, yours are the best. 🙂