Elfwurm
(Personal)
December 9, 2022, 8:26pm
1
Hello,
this is a beginner question.
word_1 = print("Please give word: ")
word_2 = print("Please give another word: ")
print(“The combined word is ‘“word_1 word_2”’”)
[input: word_1 = one, word = two]
The print should be “The combined word is ‘onetwo’”
However, it shows syntax error.
I only know to how to write this with a space:
print(“The combined word is ‘“word_1, word_2”’”)
“The combined word is ‘one two’”
How could I do this?
Thank you in advance.
MRAB
(Matthew Barnett)
December 9, 2022, 8:42pm
2
Please wrap code in triple backticks to preserve the formatting:
```python
if True:
print(''Hello world!')
```
The simplest method is probably using f-strings:
print(f"The combined word is {word_1}{word_2}")
Incidentally, when asking for a word, you should use input
because print
only prints.
1 Like
tjreedy
(Terry Jan Reedy)
December 9, 2022, 10:11pm
3
Or print(word1, word2, sep='')
. end=""
suppresses the default end='\n'
. Note: a Python-oriented editor/IDE, such as IDLE, should, after one types print(
and pauses a bit, display a call hint that shows one such options. Interactively, >>> help(print)
would do the same a bit more verbosely.
1 Like