r/PythonLearning • • Aug 14 '25

Why I didn't getting default value

Post image
5 Upvotes

18 comments sorted by

View all comments

8

u/JeLuF Aug 14 '25

Because you call the function with a parameter. Even an emtpy string is still a parameter passed to the function.

Only if you call the function without a parameter, the default would kick in. Try hello() instead to see how that changes the output.

0

u/Red_Priest0 Aug 14 '25

I want default when there is no input from user

0

u/shlepky Aug 14 '25 edited Aug 14 '25

Change the comma to + in the print function call.

1

u/JeLuF Aug 14 '25

Why? The comma is more efficient since Python will not have to concatenate two strings first. It can simply write the first item and then write the second item.

1

u/shlepky Aug 14 '25

My bad then, I though the first argument of the function needs to be what you want to print, rest would be any other parameters. I should have checked the function before assuming that.