Learn Python Episode #18: Keyword Arguments

in #technology7 years ago

Alright! So, let's talk about keyword arguments. The first keyword, or boolean, that we are going to cover is None. Basically, this is the equivalent to null in other languages. So, let's go ahead and write our previous function.

def print_something(name = "Someone", age = "Unknown"):
    print("My name is", name, "and my age is", age)

print_something(None, 27)

There isn't a way to pass in an argument that isn't first one being used unless we use keyword arguments. We can also define the variable when we call the function.

def print_something(name = "Someone", age = "Unknown"):
    print("My name is", name, "and my age is", age)

print_something(age = 27, name = "Nick")

By using keyword arguments, we can specify which value is supposed to go in a particular variable.

Get The Learn to Code Course Bundle!
https://josephdelgadillo.com/product/learn-to-code-course-bundle/

Best,
Joseph Delgadillo
Web: https://josephdelgadillo.com/
YouTube: https://www.youtube.com/c/JosephDelgadillo
Steemit: https://steemit.com/@jo3potato

Coin Marketplace

STEEM 0.24
TRX 0.11
JST 0.033
BTC 62441.28
ETH 3020.61
USDT 1.00
SBD 3.79