Greetings team,
Iam new and learning Python. Kindly help me understand the below question.
- What is the output of the following python code if we enter “Hello Python” as input?
inputString = input(‘Enter a string: ‘)
print(inputString, sep=’#’, end=‘&’)
The answer was mentioned as “Hello Python&”
Please help understand why the keyword “sep” do not work but “end” works.
1 Like
Hi @mahesh.kumar.sridhar
This is because sep
is the object separator. You have only provided one object to the print
function, which is a single string.
If the code was
inputString1 = input('Enter a string: ')
inputString2 = input('Enter another string: ')
print(inputString1, inputString2, sep='#', end='&')
and you input Hello
and Python
as the two inputs, then the result would be Hello#Python&
See Built-in Functions — Python 3.11.5 documentation
1 Like
Thank you for your response