Answers for "Python Default Arguments"

18

python default arguments

def my_function(name, age = 20):
  print(name + " is " + str(age) + " years old"

my_function("Mitro") # Mitro is 20 years old
my_function("Mitro", 26) #Mitro is 26 years old
Posted by: Guest on May-27-2020
5

python default arguments

def your_function(arg,kwarg='default'):
    return arg + kwarg
Posted by: Guest on April-08-2020
4

how to set a default parameter in python

def my_function(num1,num2=0):		#if num2 is not given, it will default it to zero
  return num1 + num2

print(my_function(1,2))				#prints out 3
print(my_function(4))				#prints out 4 since num2 got defaulted to 0
Posted by: Guest on October-25-2020
2

arguments with default parameters python

def screen_size(screen_size=80):
  return screen_aize

screen_size(120)    # the screen size is 120
screen_size()		# the screen size is 80 as default
Posted by: Guest on February-01-2021
3

python function parameters default value

def F(a, b=None):
    if b is None:
        b = []
    b.append(a)
    return b
Posted by: Guest on April-30-2020
0

Python Default Arguments

def greet(name, msg="Good morning!"):
    """
    This function greets to
    the person with the
    provided message.

    If the message is not provided,
    it defaults to "Good
    morning!"
    """

    print("Hello", name + ', ' + msg)


greet("Kate")
greet("Bruce", "How do you do?")
Posted by: Guest on May-11-2021

Code answers related to "Python Default Arguments"

Python Answers by Framework

Browse Popular Code Answers by Language