MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/PythonLearning/comments/1mpuzhh/why_i_didnt_getting_default_value/n8ma9wz/?context=3
r/PythonLearning • u/Red_Priest0 • Aug 14 '25
18 comments sorted by
View all comments
8
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.
hello()
1 u/Red_Priest0 Aug 14 '25 I want default value when there is no input from user 11 u/rebelle3 Aug 14 '25 use an if statement to determine if the user input is empty 3 u/Much_Buy7605 Aug 14 '25 Then instead of just calling it directly with name, you can do a if else with a check that name is not empty and call "hello()" if it is 3 u/niket23697 Aug 14 '25 you can check if the input is empty (or something else which you don't want) then call hello(), otherwise call hello(name) 2 u/SCD_minecraft Aug 14 '25 A = input() print(A or "world")If user inputs anything, it will print thatIf user inputs nothing, it will print world
1
I want default value when there is no input from user
11 u/rebelle3 Aug 14 '25 use an if statement to determine if the user input is empty 3 u/Much_Buy7605 Aug 14 '25 Then instead of just calling it directly with name, you can do a if else with a check that name is not empty and call "hello()" if it is 3 u/niket23697 Aug 14 '25 you can check if the input is empty (or something else which you don't want) then call hello(), otherwise call hello(name) 2 u/SCD_minecraft Aug 14 '25 A = input() print(A or "world")If user inputs anything, it will print thatIf user inputs nothing, it will print world
11
use an if statement to determine if the user input is empty
3
Then instead of just calling it directly with name, you can do a if else with a check that name is not empty and call "hello()" if it is
you can check if the input is empty (or something else which you don't want) then call hello(), otherwise call hello(name)
2
A = input() print(A or "world")
If user inputs anything, it will print that
If user inputs nothing, it will print world
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.