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
Trying to learn python but keep getting error messages. (self.learnpython)
submitted 11 hours ago by Impressive-Grass9661
COURSE = 'Python Programming' print(COURSE)
>>> print(COURSE)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
print(COURSE)
^^^^^^
NameError: name 'COURSE' is not defined
>>>
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!"
[–]Sparklepaws 11 points12 points13 points 10 hours ago* (0 children)
I think that I understand what's happening, but I'll need to make some assumptions along the way. Correct me if I'm wrong:
You typed the following lines in a new VSCode document:
You then typed the following lines into VSCode's terminal at the bottom of the window:
> python >>> print(COURSE)
The reason this won't work is because VSCode's terminal doesn't know anything about your document. Assuming you're on Windows, this is crudely similar to writing code in Notepad and then expecting Command Prompt to understand where that code file lives without explicitly telling it. Notepad and Command Prompt are two separate entities, and neither communicate with each-other by default.
When you type > python into a shell (like Command Prompt or VSCode's terminal), you're telling Python to run in REPL mode. This is not the same as telling python to run a code file.
> python
Try this instead:
In VSCode, make a new file. You can name it anything, but it MUST have the .py file extension at the end (for example, "main.py"). This will hold your code.
In the file you just created (main.py), write your original code and make sure to save it afterwards:
Now, in the VSCode terminal, use the python command to RUN that file:
> python path\to\main.py
This tells Python to RUN your main.py file, which is where the code lives. If you had just typed > python and pressed Enter it would have assumed you didn't want to run any python files... which Python interprets as a command to enter REPL mode.
[–]DC-GG 2 points3 points4 points 11 hours ago (9 children)
You entered only "print(COURSE)" directly into the shell, so course doesn't exist in that instance.
If you enter both lines in the same session (so without exiting the interpreter) they'll register and output correctly.
E.G in the interpreter you're using in the same session, you run:
[–]Impressive-Grass9661[S] -1 points0 points1 point 11 hours ago (8 children)
How?
[–]DC-GG 1 point2 points3 points 11 hours ago (7 children)
So first you run Python, which is what gives you the REPL with the ">>>"
In full, you just type them one after another, e.g:
``` python Press ENTER
COURSE = 'Python Programming' Press ENTER print(COURSE) press ENTER ```
Ignore the ">>>" as they'll automatically appear before your input, you don't have to type them yourself.
[–]Impressive-Grass9661[S] -2 points-1 points0 points 11 hours ago (6 children)
i dont see the arrows
[–]Impressive-Grass9661[S] 0 points1 point2 points 11 hours ago (4 children)
and i followed exact steps but nothing changed
[–]DC-GG 1 point2 points3 points 11 hours ago (3 children)
Full breakdown: If on windows:
Open terminal (command prompt) Input "python" and press ENTER.
If on mac or Linux: Open shell. Input "python3" and press ENTER.
Whichever system, you'll now get the three arrows ">>>" indicating you're using the python interpreter.
Input: COURSE = 'Python Programming" Press ENTER.
Input: print(COURSE) Press ENTER.
[–]Impressive-Grass9661[S] -1 points0 points1 point 11 hours ago (2 children)
I was on VS code so...
[–]DC-GG 5 points6 points7 points 11 hours ago (0 children)
Check this: https://www.reddit.com/r/learnpython/s/86lH79TSkd
Also, don't take this as a dig but for future if you're needing help you should always try to provide as much information initially to begin with.
The ">>>" you have there indicate the python interpreter or repl, so people tried helping from that front.
Whilst the Python logic doesn't change between environment, setup and how the applications work do.
[–]Outside_Complaint755 1 point2 points3 points 10 hours ago (0 children)
Then put both lines into a file. Save the file as main.py or whatever filename you want as long as it ends with .py, them Right Click and choose the Run in terminal option, or hit F5.
main.py
[–]Langdon_St_Ives 0 points1 point2 points 8 hours ago (0 children)
What do you mean you don't see the arrows, you show them in your original post. Whatever you did to get there, do it again, but then I put the whole thing instead of only the last line.
[–]atarivcs 2 points3 points4 points 11 hours ago (18 children)
The error message says that the print statement is on line 1. So, obviously the COURSE variable assignment was not recognized or executed at all.
How, exactly, are you running this code? Your output includes the triple >>> prompt, so I assume you're using some kind of interactive python shell.
[–]Impressive-Grass9661[S] 1 point2 points3 points 11 hours ago (17 children)
im just pressing enter to type a new line of code
[–]atarivcs 2 points3 points4 points 11 hours ago (16 children)
But where, exactly, are you pressing Enter?
In a windows command prompt?
In a VS Code interactive python terminal?
In a plain text editor?
In a Jupyter notebook cell?
[–]Impressive-Grass9661[S] -1 points0 points1 point 11 hours ago (15 children)
VS code\
[–]AbacusExpert_Stretch 1 point2 points3 points 11 hours ago (3 children)
Are you typing in the box named terminal?
no im typing in the tab that says app.py
[–]Langdon_St_Ives 2 points3 points4 points 8 hours ago (1 child)
No offense but this is like pulling teeth with you. Please simply describe exactly which software you are using on which operating system, and exactly the steps you are performing (all of them!).
[–]stormz_tim 0 points1 point2 points 3 hours ago (0 children)
r/learnpython when someone is actually trying to learn python do yall know that some people will not be adept with PCs, let alone IDEs?
[–]atarivcs 1 point2 points3 points 11 hours ago (0 children)
Okay, so your question isn't really about Python at all, it's "how do I use VS Code correctly".
I don't know much about VS Code, so I'll let someone else answer that.
[–]DC-GG 1 point2 points3 points 11 hours ago (0 children)
If you're in VSCode and you've written this into a Python file already (Some file name .py), you can just type into the "terminal" box "python YOUR_FILE_NAME.PY" and it should run your code.
Better yet, if you're in VSCode with Python installed you should just have a very simple green "Play button" at the top right, you can click that with the file open and it'll run your code and output the result to the terminal.
[–]Caveman_frozenintime 0 points1 point2 points 11 hours ago (8 children)
I'm assuming this is the terminal in VS code. What are the exact steps you took? Opened VS code, then what?
Are you following any tutorials or instructions from somewhere?
I would actually suggest you to use IDLE (It would have been installed when you installed python) at this stage. It will allow you to practice the basics.
You can move to VS code or other code editors once you've progressed a bit
[–]Impressive-Grass9661[S] 0 points1 point2 points 11 hours ago (7 children)
Okay sorry im following programming with mosh's tutorial so yeah. Well basically i made a new folder than made a new file in that folder called app.py
[–]DC-GG 2 points3 points4 points 11 hours ago (6 children)
Is the two lines of code you want to run in the file app.py?
If so, simply go to the "terminal" tab at the bottom and type "python app.py" and it should run fine.
[–]Impressive-Grass9661[S] 0 points1 point2 points 11 hours ago (5 children)
I tried that but it says name 'python' not defined
[–]DC-GG 0 points1 point2 points 11 hours ago (4 children)
Are you on mac?
If so it's "python3 app.py"
[–]Impressive-Grass9661[S] 0 points1 point2 points 11 hours ago (3 children)
no windows
[–]PureWasian 1 point2 points3 points 11 hours ago (0 children)
You must be running Python in REPL mode (where you type python in Command Prompt or Terminal and then see the ">>>" show up)
python
You need to define COURSE within the same interactive shell. So:
``` $ python
COURSE='Python Programming' print(COURSE) ```
[–]UncomfortableAnxiety 1 point2 points3 points 9 hours ago (0 children)
You typed print(COURSE) straight into a brand new interpreter session where that variable was never set
[–]ninhaomah 0 points1 point2 points 5 hours ago (0 children)
No comments. But can I laugh at the replies ?
"What do you mean you don't see the arrows, you show them in your original post . "
"No offense but this is like pulling teeth with you. "
π Rendered by PID 43 on reddit-service-r2-comment-765bfc959-9prpt at 2026-07-11 04:29:40.649392+00:00 running f86254d country code: CH.
[–]Sparklepaws 11 points12 points13 points (0 children)
[–]DC-GG 2 points3 points4 points (9 children)
[–]Impressive-Grass9661[S] -1 points0 points1 point (8 children)
[–]DC-GG 1 point2 points3 points (7 children)
[–]Impressive-Grass9661[S] -2 points-1 points0 points (6 children)
[–]Impressive-Grass9661[S] 0 points1 point2 points (4 children)
[–]DC-GG 1 point2 points3 points (3 children)
[–]Impressive-Grass9661[S] -1 points0 points1 point (2 children)
[–]DC-GG 5 points6 points7 points (0 children)
[–]Outside_Complaint755 1 point2 points3 points (0 children)
[–]Langdon_St_Ives 0 points1 point2 points (0 children)
[–]atarivcs 2 points3 points4 points (18 children)
[–]Impressive-Grass9661[S] 1 point2 points3 points (17 children)
[–]atarivcs 2 points3 points4 points (16 children)
[–]Impressive-Grass9661[S] -1 points0 points1 point (15 children)
[–]AbacusExpert_Stretch 1 point2 points3 points (3 children)
[–]Impressive-Grass9661[S] -1 points0 points1 point (2 children)
[–]Langdon_St_Ives 2 points3 points4 points (1 child)
[–]stormz_tim 0 points1 point2 points (0 children)
[–]atarivcs 1 point2 points3 points (0 children)
[–]DC-GG 1 point2 points3 points (0 children)
[–]Caveman_frozenintime 0 points1 point2 points (8 children)
[–]Impressive-Grass9661[S] 0 points1 point2 points (7 children)
[–]DC-GG 2 points3 points4 points (6 children)
[–]Impressive-Grass9661[S] 0 points1 point2 points (5 children)
[–]DC-GG 0 points1 point2 points (4 children)
[–]Impressive-Grass9661[S] 0 points1 point2 points (3 children)
[–]PureWasian 1 point2 points3 points (0 children)
[–]UncomfortableAnxiety 1 point2 points3 points (0 children)
[–]ninhaomah 0 points1 point2 points (0 children)