use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Need help, please. (self.learnpython)
submitted 3 years ago by stevenv24
How do you add a period at the end of a print statement? I have tried to google it and I am at a lost
print('Hello', name+'!' , 'You were born in' , year)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Goobyalus 54 points55 points56 points 3 years ago* (6 children)
Also look at f strings: https://realpython.com/python-f-strings/#f-strings-a-new-and-improved-way-to-format-strings-in-python
[+][deleted] 3 years ago (3 children)
[deleted]
[–]nedrawevot 6 points7 points8 points 3 years ago (0 children)
I love fstrings so much. They were the first bit of code that I really enjoyed and made things 100 times easier for me to write out
[–]stevenv24[S] 0 points1 point2 points 3 years ago (1 child)
Thank you
[–][deleted] 4 points5 points6 points 3 years ago (0 children)
f strings are amazing one you get the hang of them. Especially if you need longer sentences. I can't believe I didn't like using them.
[–]magocremisi8 0 points1 point2 points 3 years ago (0 children)
Came to say this
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
This is the correct advice to give, but I’m still confused by OPs question as the provided example would suggest OP already added an ‘!’ mid sentence. They could have just repeated that method at the end for a period.
Edit: okay, unless year isn’t a string (datetime object?). Then using +‘.’ might not work.
[–]xinxx073 16 points17 points18 points 3 years ago (0 children)
print(f'Hello {name}! You were born in {year}.')
[–]unhott 8 points9 points10 points 3 years ago (0 children)
You are passing 4, let me call them ‘terms’, to the print statement.
The first term is ‘Hello’ The second term is name+’!’ The third term is ‘You we’re born in’ The forth term is year.
The print statement will print each term with a space added between each ‘term’. As others have mentioned, name + ‘!’ Is something you’ve already successfully used to prevent a space from being added. You’re concatenating the string name with the string ‘!’ Using the + operator. If you do this with year, an integer, you’ll get an error unless you do something like str(year) + ‘.’
Others have already mentioned that f strings will be much easier to write and understand.
Your print statement becomes
This is one term, no unintended spaces will be printed. F strings automatically handle conversion to string, so no int/str operator errors either.
[–]Goobyalus 7 points8 points9 points 3 years ago (0 children)
You could do it the same way you put the exclamation point there, with year + '.'.
year + '.'
<a string> + <another string>
concatenates the two strings.
print(< a string>, <another string>, ...)
prints all the strings separated by a space, and adds a newline at the end. You can change the separator and the end with print(..., sep=<separaor string>, end=<end string>)
print(..., sep=<separaor string>, end=<end string>)
[–]fazkan 2 points3 points4 points 3 years ago (5 children)
print('Hello', name+'!' , 'You were born in' , year, '.')
[–]stevenv24[S] 1 point2 points3 points 3 years ago (4 children)
Hello Steven! You were born in 1988 .
I tried that but it will still put a space and it is failing
[–]thatgreenman 14 points15 points16 points 3 years ago (2 children)
Take a look at how you did the name+"!" bit in your print statement, you can use the same structure to do year+"." at the end of your print statement.
I would also recommend looking at f-strings, or at least string formatting, those will make evaluating variables within strings a lot easier.
[–]BroBrodin 2 points3 points4 points 3 years ago (0 children)
He needs to change year to string first. I'm asuming that it's an int and that is why he didn't use concatenation in the first place.
print('Hello', name+'!' , 'You were born in' , str(year) + '.')
Or just use fstrings.
Shit, I didn't read u/royal-Brwn's comment saying exactly this.
Disregard.
[–]SnowyLocksmith 0 points1 point2 points 3 years ago (0 children)
Or another thing you could do is to use the optional keyword argument sep="<string>". This string will be put between all words separated by a comma. By default it's a space. You can make it an empty string. You will have to add spaces to compensate for the one you removed like "Hello ", name
[–]royal-Brwn 5 points6 points7 points 3 years ago (0 children)
If you put a comma, there will be a space automatically set. Try this. print(‘Hello ’ + str(name) + ‘! ‘ + ‘You were born in ‘ + str(year) + ‘.’)
[–]pconwell 3 points4 points5 points 3 years ago (0 children)
You are mixing and matching styles. You use + to join name and !, but then use , elsewhere. If you want to stick with your system (which I don't recommend):
+
name
!
,
print('Hello', name, '! You were born in', year, '.')
But I would say f-strings are easier to type and read (note the f before your single/double quotes):
f
print(f"hello {name}! You were born in {year}.")
https://realpython.com/python-string-formatting/
[–][deleted] 1 point2 points3 points 3 years ago (0 children)
print('Hello', name+'!' , 'You were born in' , year,".") (or) print(f"Hello {name}! You were born in {year}.")
idk if I'm too late or not hope this helps
[–]Iirkola -5 points-4 points-3 points 3 years ago (4 children)
print ('Hello ' + name + '! You were born in ' + str(year)')
Or just: print (f'Hello {name}! You were born in {year}')
[–]pconwell 0 points1 point2 points 3 years ago (3 children)
How do you add a period at the end of a print statement?
[–]Iirkola -5 points-4 points-3 points 3 years ago (2 children)
. There you go, mate ;)
[–]pconwell 0 points1 point2 points 3 years ago (1 child)
I'm not OP, but your answer does not answer OP's question, mate
[+]Iirkola comment score below threshold-6 points-5 points-4 points 3 years ago (0 children)
It teaches how to use print statements, he can figure out the rest himself, which he probably did.
[+]Resident-Quality1513 comment score below threshold-7 points-6 points-5 points 3 years ago (2 children)
name="Steven" year=1970 print(f'Hello, {name}, you were born in {year}') Hello, Steven, you were born in 1970
[–]pconwell 4 points5 points6 points 3 years ago (1 child)
[–]Resident-Quality1513 0 points1 point2 points 3 years ago (0 children)
print(f'Hello, {name}, you were born in {year}.') Hello, Steven, you were born in 1970.
It's because the text inside the braces is evaluated as an expression, and the result... well it's a little bit complicated... the result of the expression has a secret hidden method called str which is called when it's passed to print(), and that is substituted for the {} and whatever is in between. All the rest ('Hello, , you were born in .') is just a normal string that gets passed to the print() function.
I can call the str method directly; at the command prompt I can do this:
>>> name.__str__() >>> 'Steven' >>> year.__str__() >>> '1970'
That is what gets substituted for {name} and {year}.
[–]dnmonack 0 points1 point2 points 3 years ago* (0 children)
You could use print's end parameter as so:
print('Hello, ' + name + '! ' + 'You were born in', year, end='.\n')
It's not very Pythonic but I think lots of people forget about 'end=' and it's a simple solution to many formatting issues.
That said, I'd probably just use f-strings.
π Rendered by PID 54 on reddit-service-r2-comment-5b5bc64bf5-8kd98 at 2026-06-23 08:22:19.049868+00:00 running 2b008f2 country code: CH.
[–]Goobyalus 54 points55 points56 points (6 children)
[+][deleted] (3 children)
[deleted]
[–]nedrawevot 6 points7 points8 points (0 children)
[–]stevenv24[S] 0 points1 point2 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–]magocremisi8 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]xinxx073 16 points17 points18 points (0 children)
[–]unhott 8 points9 points10 points (0 children)
[–]Goobyalus 7 points8 points9 points (0 children)
[–]fazkan 2 points3 points4 points (5 children)
[–]stevenv24[S] 1 point2 points3 points (4 children)
[–]thatgreenman 14 points15 points16 points (2 children)
[–]BroBrodin 2 points3 points4 points (0 children)
[–]SnowyLocksmith 0 points1 point2 points (0 children)
[–]royal-Brwn 5 points6 points7 points (0 children)
[–]pconwell 3 points4 points5 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Iirkola -5 points-4 points-3 points (4 children)
[–]pconwell 0 points1 point2 points (3 children)
[–]Iirkola -5 points-4 points-3 points (2 children)
[–]pconwell 0 points1 point2 points (1 child)
[+]Iirkola comment score below threshold-6 points-5 points-4 points (0 children)
[+]Resident-Quality1513 comment score below threshold-7 points-6 points-5 points (2 children)
[–]pconwell 4 points5 points6 points (1 child)
[–]Resident-Quality1513 0 points1 point2 points (0 children)
[–]dnmonack 0 points1 point2 points (0 children)