Computer Science, asked by AvinavSingh7983, 9 months ago

Write a program to illustrate ""default argument"".

Answers

Answered by NirmalPandya
0

def brainly_student(first_name, last_name = 'lee', id = 'NULL'):

   print('id  last_name  first_name :: ',id, last_name, first_name)

brainly_student(first_name = 'Dheer', id = 456 )

brainly_student(last_name = 'Aziz')

output:

id  last_name  first_name ::  456 lee Dheer

Traceback (most recent call last):

line 4, in <module>

   brainly_student(last_name = 'Aziz')

TypeError: brainly_student() missing 1 required positional argument: 'first_name'

program to illustrate "default argument".

  • the above program prints id, last_name, first_name and has two default argument namly last_name and id
  • default arguments are always placed at end
  • at first we provide first_name and id but not the last_name yet it prints all the values picking the value of last_name from the default value but on second line it throws up error as first_name is not provided and it is not a default argument
  • so value of default argument may or may not be provided but we must provide the values for all non-default arguments
Similar questions