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.

1

u/Red_Priest0 Aug 14 '25

I want default value when there is no input from user

2

u/SCD_minecraft Aug 14 '25
A = input()
print(A or "world")

If user inputs anything, it will print that

If user inputs nothing, it will print world