Default arguments and positional arguments in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Default arguments and positional arguments in Python

1. Define a function called user_name_definition with two arguments: f_name and l_name similar to the above example. 2. Set the default value for f_name to be "John" 3. Set the default value for l_name to be "Doe" Syntax:- def user_name_definition(name1, name2): return name1 + ' ' + name2 f_name = "John" l_name = "Doe" print(user_name_definition(f_name, l_name)) or def user_name_definition(f_name, l_name): return f_name + ' ' + l_name f_name = "John" l_name = "Doe" print(user_name_definition(f_name, l_name)) Out Put: John Doe however I'm getting bellow validation issue:- Define user_name_defintion function Description Searched your code for a specific pattern: def\s*user_name_definition\s*\(\s*f_name\s*=\s*['"]John['"]\s*,\s*l_name\s*=\s*['"]Doe['"]\s*\)

24th Sep 2020, 9:34 AM
Abhi
Abhi - avatar
2 Answers
0
Hi HBhZ_C, Thanks for your prompt response and I got the correct syntax as below. def user_name_definition(f_name='John', l_name='Doe'): return f_name + ' ' + l_name f_name = "John" l_name = "Doe" print(user_name_definition(f_name, l_name))
24th Sep 2020, 10:22 AM
Abhi
Abhi - avatar
+ 4
default value for any parameter will be in function definition not in function call so when defined params for the function set their default value: def func(fname="Jhon",lname="Doe"){ }
24th Sep 2020, 9:41 AM
HBhZ_C
HBhZ_C - avatar