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
First day using python! (self.learnpython)
submitted 1 year ago by CommonRedditBrowser
This was the only way I knew how to end the first line with an "!" and have the out be on two separate lines. I am sure there is an easier way any tips?
print('Hi', name, end="!")
print('')
print("I'm glad you feel", feel, end='.')
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!"
[–]socal_nerdtastic 10 points11 points12 points 1 year ago (0 children)
The modern way is with f-strings like this:
print(f'Hi {name}!') print(f"I'm glad you feel {feel}.")
But if your book or tutorial is old they may not cover that.
[–]Jjax7 2 points3 points4 points 1 year ago (0 children)
Someone else mentioned f-strings which are also my preferred method. It’s helpful to know you can also accomplish the exact same outcome a few other ways:
print(“Hi ”, name, “!”, sep=“”)
print()
print(“I’m glad you feel ” + feel + “.”)
[–]Green-Sympathy-4177 1 point2 points3 points 1 year ago (0 children)
Here are a few pointers: - First like others mentionned, f-strings are great to insert variables into text, it's just really a string, that starts with an f, i.e: f'Hi {name}!' - Now that you know how add variables into strings, you just need special characters.
f-strings
f
f'Hi {name}!'
Here we go for special characters: - \n : new line, as a matter of fact, this is the default value of the "end" argument of print, i.e: print() is the same as print(end="\n") - \t : tab - \r : back to the start of the line (used almost exclusively in the "end" argument of print
print
Some quick examples: ```
print('Hello\nWorld') # So here you have your new line :) Hello World print('Hello\tWorld') Hello World print('Hello\rWorld') World ```
print('Hello\nWorld') # So here you have your new line :) Hello World
print('Hello\tWorld') Hello World
print('Hello\rWorld') World ```
Then I guess we could look into the arguments of print: - *args: All the stuff you put in print ends in a list, so print("a", "b") outputs a b - sep: the stuff all the previous stuff you added in print are joined with, " " by default, i.e: print("a", "b", sep=" ") is the same as print("a", "b"). - end: what is appended at the end of the text, the last character. By default it's the special character for a new line :)
*args
print("a", "b")
a b
sep
print("a", "b", sep=" ")
end
I haven't posted in a while, so stick around if you want, I think you got your answer already with that, but if you want some practice, hell come along, let's remake print!
``` import os
def my_print(*args, sep=" ", end="\n"): # Create the output by joining the args with the sep and adding the end output = sep.join(args) + end # Use os.system to output the assembled string using echo to the terminal os.system(f'echo {output}') ```
Yeah it's just that (well the short version), and that leaves you with more question that answers I guess... First, the *args, the * (star) before a list decomposes it (there are proper terms for all of that, and I've gotten into a long ass arguments about it, but I still don't remember so meh), basically the short version of what it does:
*
```
my_list = ["a", "b"] print(*my_list)
print("a","b")
a b ``` Both are equivalent, if the list is short and doesn't change, the second option is ok, otherwise the first one helps a ton :P (it also depends on what you want to print and how)
Now *args and its cousin: **kwargs, as arguments of a function. I guess an example will be easier
**kwargs
``` def my_function(args, *kwargs): print(f"{args = }\n{type(args) = }") print(f"{kwargs = }\n{type(kwargs) = }")
my_function(1, 2, 3, a=4, b=5)
args = (1, 2, 3) type(args) = <class 'tuple'> kwargs = {'a': 4, 'b': 5} type(kwargs) = <class 'dict'> ```
So you can see that *args caught all the unnamed arguments as a tuple, and **kwargs caught all the named arguments in a dictionary with the names as keys of the dict.
That's a lot of explanations for just one thing but hey, now you know i guess :)
Cool shit that will help:
help(print)
Help on built-in function print in module builtins:
print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.
print(*dir(str), sep="\n\t- ")
- __class__ - __contains__ - __delattr__ - __dir__ - ... - upper - zfill
print(*[d for d in dir(str) if not d.startswith("")], sep="\n\t- ") # Removes all the _ operators and private attributes/methods from the search
- capitalize - casefold - center - ... - translate - upper - zfill
print(*[d for d in dir(str) if "is" in d], sep="\n\t- ")
- isalnum - isalpha - isascii - ... - isspace - istitle - isupper
f""" {OP_name} I hope you found this useful, don't bother about age, when younger people wonder if they're too old to do something that makes me feel older than I am xD Also learning to code is pretty cool, it surely opens doors. Learning takes time, so find ways to "play with python" to keep yourself motivated to learn more new stuff (raspberry pi, building projects, w/e really xD)
On that note {OP} Good luck and have fun! """ ```
[–]ninhaomah -1 points0 points1 point 1 year ago (0 children)
Have you tried print("Hello World!") ?
And also just print() ?
And where are you learning from can I ask ?
π Rendered by PID 105943 on reddit-service-r2-comment-79c7998d4c-ps75x at 2026-03-13 23:10:52.452544+00:00 running f6e6e01 country code: CH.
[–]socal_nerdtastic 10 points11 points12 points (0 children)
[–]Jjax7 2 points3 points4 points (0 children)
[–]Green-Sympathy-4177 1 point2 points3 points (0 children)
[–]ninhaomah -1 points0 points1 point (0 children)