1
word1 = input("Random Name (ex. Ryan):")
word2 = input("Your name (ex. why do you need an example of your name?):")

print("To:", word1, "@gmail.com")
print("From:", word2, "@outlook.com")

Now you almost need to ignore everything except, word 1 and word2 for now.

Im just wondering why is that the output is

To:name @gmail.com  

and not To:[email protected]

Thanks in advance guys!

2 Answers 2

3

You can do

print("To:" + word1 + "@gmail.com")

Or

print("To:%[email protected]" % word1) 

Or

print("To:{}@gmail.com".format(word1)) 

Or as suggested in the comment:

print("To:{0:s}@gmail.com".format(word1))

To print the value the way you want

Doing print(some_val, some_val2, some_val3, ...) will add a space between these values.

Sign up to request clarification or add additional context in comments.

1 Comment

I would use print("To:{0:s}@gmail.com".format(word1)) so that the {} make sense to people who haven't seen this notation. The 0 being the first item to format and the s meaning a string.
3

Because in python print automatically adds spaces between the arguments of the print statement, i.e., things separated by commas. If you want to remove that, you can set the sep keyword to a different separator besides a space. Set it to a blank string to have no separator.

>>> print('A','string','with','spaces.')
A string with spaces.
>>> print('A','string','with','no','spaces.', sep = '')
Astringwithnospaces.

2 Comments

even if I would say the other answer is the way to go it's really nice to knw that you can change the seperator in the print function
The other answer offers more control over formatting, but this is useful too. Note there's also an end keyword that species/changes what is appended to the end of the string. By default it is a newline, \n, but you can set it to '' to not print out to a new line.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.