|
| https://realpython.com/ |
| Start Here | https://realpython.com/start-here/ |
|
Learn Python
| https://realpython.com/videos/write-python-script/ |
| Python Tutorials →In-depth articles and video courses | https://realpython.com/search?kind=article&kind=course&order=newest |
| Learning Paths →Guided study plans for accelerated learning | https://realpython.com/learning-paths/ |
| Quizzes & Exercises →Check your learning progress | https://realpython.com/quizzes/ |
| Browse Topics →Focus on a specific area or skill level | https://realpython.com/tutorials/all/ |
| Community Chat →Learn with other Pythonistas | https://realpython.com/community/ |
| Office Hours →Live Q&A calls with Python experts | https://realpython.com/office-hours/ |
| Podcast →Hear what’s new in the world of Python | https://realpython.com/podcasts/rpp/ |
| Books →Round out your knowledge and learn offline | https://realpython.com/products/books/ |
| Reference →Concise definitions for common Python terms | https://realpython.com/ref/ |
| Code Mentor →BetaPersonalized code assistance & learning tools | https://realpython.com/mentor/ |
| Unlock All Content → | https://realpython.com/account/join/ |
|
More
| https://realpython.com/videos/write-python-script/ |
| Learner Stories | https://realpython.com/learner-stories/ |
| Python Newsletter | https://realpython.com/newsletter/ |
| Python Job Board | https://www.pythonjobshq.com |
| Meet the Team | https://realpython.com/team/ |
| Become a Tutorial Writer | https://realpython.com/write-for-us/ |
| Become a Video Instructor | https://realpython.com/become-an-instructor/ |
| Search | https://realpython.com/search |
| https://realpython.com/search |
| Join | https://realpython.com/account/join/ |
| Sign‑In | https://realpython.com/account/login/?next=%2Fvideos%2Fwrite-python-script%2F |
| https://realpython.com/courses/python-basics-first-program/#team |
| Python Basics: Code Your First Python Program | https://realpython.com/courses/python-basics-first-program/ |
| Christopher Bailey | https://realpython.com/courses/python-basics-first-program/#team |
| Course Slides (.pdf) | https://realpython.com/courses/python-basics-first-program/downloads/python-basics-first-program-slides/ |
| Ask a Question | https://realpython.com/videos/write-python-script/#discussion |
| https://realpython.com/feedback/survey/course/python-basics-first-program/liked/?from=lesson-title |
| https://realpython.com/feedback/survey/course/python-basics-first-program/disliked/?from=lesson-title |
| Contents | https://realpython.com/videos/write-python-script/#description |
| Transcript | https://realpython.com/videos/write-python-script/#transcript |
| Discussion (11) | https://realpython.com/videos/write-python-script/#discussion |
| Getting Started With Python IDLE | https://realpython.com/python-idle/ |
| Interacting With Python | https://realpython.com/interacting-with-python/ |
| Your Guide to the Python print() Function | https://realpython.com/python-print/ |
| 00:00 | https://realpython.com/videos/write-python-script/#t=0.48 |
| Okay. It’s time to get started writing your Python script. | https://realpython.com/videos/write-python-script/#t=0.48 |
| 00:05 | https://realpython.com/videos/write-python-script/#t=5.41 |
| You’re going to be using a program that comes with your installation of Python. | https://realpython.com/videos/write-python-script/#t=5.41 |
| It’s called IDLE, | https://realpython.com/videos/write-python-script/#t=8.74 |
| which stands for Integrated Development and Learning Environment. | https://realpython.com/videos/write-python-script/#t=10.0 |
| 00:13 | https://realpython.com/videos/write-python-script/#t=13.93 |
| It has two main windows, and you’ll spend some time in both of them. | https://realpython.com/videos/write-python-script/#t=13.93 |
| The first is called the interactive window, | https://realpython.com/videos/write-python-script/#t=18.16 |
| and I’ll share that in just a second. Then the editor window, | https://realpython.com/videos/write-python-script/#t=19.84 |
| which is where you actually write scripts and programs that you’ll save and run | https://realpython.com/videos/write-python-script/#t=23.26 |
| later. All right, let’s take a look at the interactive window. | https://realpython.com/videos/write-python-script/#t=26.53 |
| 00:31 | https://realpython.com/videos/write-python-script/#t=31.44 |
| If you don’t already have IDLE open, then go ahead and open it. | https://realpython.com/videos/write-python-script/#t=31.44 |
| You can find it in the folder that the application was installed in. | https://realpython.com/videos/write-python-script/#t=35.13 |
| So in my case, I have several versions of Python here, | https://realpython.com/videos/write-python-script/#t=38.67 |
| and I’m going to choose Python 3.10 | https://realpython.com/videos/write-python-script/#t=41.55 |
| and double-click on the IDLE app. IDLE’s | https://realpython.com/videos/write-python-script/#t=45.18 |
| interactive window contains a Python shell. You can see this name up here, | https://realpython.com/videos/write-python-script/#t=49.66 |
| IDLE Shell. | https://realpython.com/videos/write-python-script/#t=53.29 |
| 00:55 | https://realpython.com/videos/write-python-script/#t=55.51 |
| It’s a textual user interface used to interact with the Python language. | https://realpython.com/videos/write-python-script/#t=55.51 |
| You can type a bit of Python code into the interactive window and press Enter to | https://realpython.com/videos/write-python-script/#t=60.4 |
| immediately see the result, hence the name interactive. | https://realpython.com/videos/write-python-script/#t=65.2 |
| 01:08 | https://realpython.com/videos/write-python-script/#t=68.86 |
| When the window opens up, it’ll display this same text at the beginning. | https://realpython.com/videos/write-python-script/#t=68.86 |
| The text shows the version of Python that IDLE is running | https://realpython.com/videos/write-python-script/#t=73.42 |
| and some of the commands you can use to get help or view information about | https://realpython.com/videos/write-python-script/#t=76.54 |
| Python. This spot over here, | https://realpython.com/videos/write-python-script/#t=80.38 |
| this is called the prompt, and it’s where you’re going to be able to type code. | https://realpython.com/videos/write-python-script/#t=83.11 |
| 01:27 | https://realpython.com/videos/write-python-script/#t=87.61 |
| So right in front of this cursor prompt, | https://realpython.com/videos/write-python-script/#t=87.61 |
| go ahead and type in 1 + 1 and then hit Enter. | https://realpython.com/videos/write-python-script/#t=90.16 |
| And you can see that it output 2. Python evaluates this expression | https://realpython.com/videos/write-python-script/#t=95.26 |
| of 1 + 1 and displays 2, | https://realpython.com/videos/write-python-script/#t=100.21 |
| and then it displays yet another prompt just below that. Every time that you run | https://realpython.com/videos/write-python-script/#t=103.93 |
| code in the interactive window, | https://realpython.com/videos/write-python-script/#t=108.22 |
| a new prompt is going to appear directly below the result. | https://realpython.com/videos/write-python-script/#t=109.9 |
| 01:55 | https://realpython.com/videos/write-python-script/#t=115.2 |
| When using the interactive window, | https://realpython.com/videos/write-python-script/#t=115.2 |
| it works as a loop and includes these three different steps. | https://realpython.com/videos/write-python-script/#t=117.03 |
| Python reads the code that you’ve entered at the prompt—that’s, again, | https://realpython.com/videos/write-python-script/#t=120.96 |
| the thing with the three different little greater than (>) symbols— | https://realpython.com/videos/write-python-script/#t=123.99 |
| and then it evaluates the code. | https://realpython.com/videos/write-python-script/#t=127.17 |
| 02:09 | https://realpython.com/videos/write-python-script/#t=129.57 |
| Python will print the result and wait for more input. | https://realpython.com/videos/write-python-script/#t=129.57 |
| This is referred to as a Read-Evaluate-Print Loop. | https://realpython.com/videos/write-python-script/#t=133.41 |
| We usually abbreviate it as REPL, R-E-P-L. Python | https://realpython.com/videos/write-python-script/#t=137.61 |
| programmers typically refer to this Python shell as the Python REPL, | https://realpython.com/videos/write-python-script/#t=142.56 |
| or just REPL for short. Okay, | https://realpython.com/videos/write-python-script/#t=147.93 |
| let’s try something a little more interesting than just adding numbers. | https://realpython.com/videos/write-python-script/#t=151.71 |
| 02:35 | https://realpython.com/videos/write-python-script/#t=155.25 |
| A rite of passage for every programmer is writing the program that prints the | https://realpython.com/videos/write-python-script/#t=155.25 |
| phrase Hello, World on the screen. At the prompt, | https://realpython.com/videos/write-python-script/#t=159.54 |
| go ahead and type in print, | https://realpython.com/videos/write-python-script/#t=163.59 |
| and then you can create a set of parentheses (()) here. | https://realpython.com/videos/write-python-script/#t=166.29 |
| 02:49 | https://realpython.com/videos/write-python-script/#t=169.89 |
| So I’m opening the parentheses, and you can see it’s giving me a little bit of | https://realpython.com/videos/write-python-script/#t=169.89 |
| additional instruction here, which is kind of nice. | https://realpython.com/videos/write-python-script/#t=173.76 |
| And we’ll learn all about this stuff as we go throughout the courses. | https://realpython.com/videos/write-python-script/#t=175.8 |
| 02:59 | https://realpython.com/videos/write-python-script/#t=179.92 |
| In this case, we’re going to print some text. So we want "Hello, World". | https://realpython.com/videos/write-python-script/#t=179.92 |
| And if I hit Return, | https://realpython.com/videos/write-python-script/#t=184.72 |
| 03:11 | https://realpython.com/videos/write-python-script/#t=191.06 |
| you can see that it outputs Hello, World. | https://realpython.com/videos/write-python-script/#t=191.06 |
| This bit of code that you typed in here, print(), is a function. | https://realpython.com/videos/write-python-script/#t=193.76 |
| A function is code that performs some task and can be invoked by its name. | https://realpython.com/videos/write-python-script/#t=197.96 |
| 03:23 | https://realpython.com/videos/write-python-script/#t=203.36 |
| The above code invokes, or calls, the print() function with the text | https://realpython.com/videos/write-python-script/#t=203.36 |
| Hello, World inside of it and outputs it. | https://realpython.com/videos/write-python-script/#t=207.71 |
| The parentheses tell Python to call the print() function. | https://realpython.com/videos/write-python-script/#t=211.52 |
| 03:35 | https://realpython.com/videos/write-python-script/#t=215.96 |
| If I just type print by itself, it won’t know that I want to call it. | https://realpython.com/videos/write-python-script/#t=215.96 |
| It’ll just tell me about it. | https://realpython.com/videos/write-python-script/#t=220.16 |
| It tells me that it’s a built-in function named print. In order to call that | https://realpython.com/videos/write-python-script/#t=222.86 |
| function, | https://realpython.com/videos/write-python-script/#t=227.84 |
| I need to put the parentheses and then tell it something, a value, as you | https://realpython.com/videos/write-python-script/#t=228.26 |
| see it’s prompting me here to put in there. And last time we typed the same thing. | https://realpython.com/videos/write-python-script/#t=233.09 |
| 03:57 | https://realpython.com/videos/write-python-script/#t=237.83 |
| So I’ll do it again. Great. | https://realpython.com/videos/write-python-script/#t=237.83 |
| Those parentheses also enclose | https://realpython.com/videos/write-python-script/#t=241.19 |
| everything that gets sent to the function, goes into it as an input. | https://realpython.com/videos/write-python-script/#t=242.93 |
| And the quotation marks ("") indicate that Hello, World is really text and | https://realpython.com/videos/write-python-script/#t=247.34 |
| not something else that we might want to print. Inside of IDLE, | https://realpython.com/videos/write-python-script/#t=252.23 |
| you can kind of see some interesting highlighting going on with different colors. | https://realpython.com/videos/write-python-script/#t=256.37 |
| 04:20 | https://realpython.com/videos/write-python-script/#t=260.33 |
| With the current setup that I have, | https://realpython.com/videos/write-python-script/#t=260.33 |
| you can see that a function is different than the output, | https://realpython.com/videos/write-python-script/#t=261.92 |
| and you can see that something that’s inside of quotation marks looks different | https://realpython.com/videos/write-python-script/#t=265.01 |
| than, say, these numbers up here. By default, functions are | https://realpython.com/videos/write-python-script/#t=269.15 |
| highlighted in purple and text is highlighted in green. | https://realpython.com/videos/write-python-script/#t=274.04 |
| 04:37 | https://realpython.com/videos/write-python-script/#t=277.64 |
| This interactive window is really useful for trying out small code examples and | https://realpython.com/videos/write-python-script/#t=277.64 |
| exploring the Python language, but it has a big limitation. | https://realpython.com/videos/write-python-script/#t=281.39 |
| You have to enter the code one line at a time. So alternatively, | https://realpython.com/videos/write-python-script/#t=285.89 |
| you can save Python code in the text file and execute all that code in order to | https://realpython.com/videos/write-python-script/#t=290.33 |
| run an entire program. | https://realpython.com/videos/write-python-script/#t=294.98 |
| 04:57 | https://realpython.com/videos/write-python-script/#t=297.23 |
| That’s where we’re going to switch into using the editor window. | https://realpython.com/videos/write-python-script/#t=297.23 |
| 05:01 | https://realpython.com/videos/write-python-script/#t=301.71 |
| You’ll write your own Python files using IDLE’s editor window. | https://realpython.com/videos/write-python-script/#t=301.71 |
| You can open the editor window by selecting File and New File from the menu at | https://realpython.com/videos/write-python-script/#t=305.4 |
| the top of the interactive window. Let me show you that. | https://realpython.com/videos/write-python-script/#t=309.69 |
| 05:14 | https://realpython.com/videos/write-python-script/#t=314.61 |
| The interactive window is going to stay open when you open the editor window. | https://realpython.com/videos/write-python-script/#t=314.61 |
| It displays the output generated by code in the editor window. | https://realpython.com/videos/write-python-script/#t=318.24 |
| So you’ll want to arrange the two windows so that you can see them both at the | https://realpython.com/videos/write-python-script/#t=322.02 |
| same time. | https://realpython.com/videos/write-python-script/#t=325.65 |
| 05:27 | https://realpython.com/videos/write-python-script/#t=327.84 |
| Inside the editor window, type in the same code you used to print Hello, World in | https://realpython.com/videos/write-python-script/#t=327.84 |
| the interactive window. Note that IDLE highlights code typed into the editor | https://realpython.com/videos/write-python-script/#t=331.92 |
| window just like it did in the interactive window. | https://realpython.com/videos/write-python-script/#t=335.88 |
| 05:38 | https://realpython.com/videos/write-python-script/#t=338.4 |
| You don’t have to add the prompt as it was in the interactive window. | https://realpython.com/videos/write-python-script/#t=338.4 |
| It’s not required. Before you can run the program, | https://realpython.com/videos/write-python-script/#t=341.82 |
| you need to save it. | https://realpython.com/videos/write-python-script/#t=346.39 |
| So select File and Save from the menu, and save the file as | https://realpython.com/videos/write-python-script/#t=347.44 |
| hello_world.py. | https://realpython.com/videos/write-python-script/#t=352.06 |
| 05:56 | https://realpython.com/videos/write-python-script/#t=356.23 |
| On some systems, | https://realpython.com/videos/write-python-script/#t=356.23 |
| it’ll use a default directory of where Python’s installed, the same place that | https://realpython.com/videos/write-python-script/#t=357.41 |
| IDLE is. | https://realpython.com/videos/write-python-script/#t=362.24 |
| Make sure that you don’t save your files in that directory. Instead save them to | https://realpython.com/videos/write-python-script/#t=363.11 |
| your desktop or to a folder in your user’s home directory. | https://realpython.com/videos/write-python-script/#t=367.31 |
| 06:11 | https://realpython.com/videos/write-python-script/#t=371.63 |
| The .py extension indicates the file contains Python code. In fact, | https://realpython.com/videos/write-python-script/#t=371.63 |
| saving your file with any other extension is going to remove the code | https://realpython.com/videos/write-python-script/#t=376.07 |
| highlighting. IDLE only will highlight Python code when it’s stored in a .py | https://realpython.com/videos/write-python-script/#t=379.73 |
| file. To run the program, you can select Run | https://realpython.com/videos/write-python-script/#t=384.53 |
| 06:31 | https://realpython.com/videos/write-python-script/#t=391.2 |
| from the pull-down menu and Run Module. | https://realpython.com/videos/write-python-script/#t=391.2 |
| You also might notice some key commands being highlighted here. In this case, | https://realpython.com/videos/write-python-script/#t=394.23 |
| it’s the function key F5. | https://realpython.com/videos/write-python-script/#t=398.43 |
| 06:44 | https://realpython.com/videos/write-python-script/#t=404.3 |
| So the program is going to output to the interactive window. You’ll see | https://realpython.com/videos/write-python-script/#t=404.3 |
| RESTART | https://realpython.com/videos/write-python-script/#t=408.44 |
| and then the directory and the name of the file that’s being run and its | https://realpython.com/videos/write-python-script/#t=409.04 |
| output. IDLE restarts the Python interpreter each time, | https://realpython.com/videos/write-python-script/#t=413.78 |
| which is the computer program that actually executes your code | https://realpython.com/videos/write-python-script/#t=418.37 |
| when you run a file. | https://realpython.com/videos/write-python-script/#t=421.85 |
| 07:03 | https://realpython.com/videos/write-python-script/#t=423.26 |
| This makes sure that programs are executed the same way each time. | https://realpython.com/videos/write-python-script/#t=423.26 |
| 07:07 | https://realpython.com/videos/write-python-script/#t=427.88 |
| If you wanted to open a file, | https://realpython.com/videos/write-python-script/#t=427.88 |
| you can go to File and Open. | https://realpython.com/videos/write-python-script/#t=429.65 |
| And in my case, | https://realpython.com/videos/write-python-script/#t=434.51 |
| I’m reopening the file that we just saved under my home directory, | https://realpython.com/videos/write-python-script/#t=435.68 |
| python_basics/, your_first_program/, and hello_world.py. | https://realpython.com/videos/write-python-script/#t=440.18 |
| 07:25 | https://realpython.com/videos/write-python-script/#t=445.65 |
| You can also open a file from the file manager, such as Windows Explorer | https://realpython.com/videos/write-python-script/#t=445.65 |
| or the macOS Finder, by right-clicking on them and say Open with. | https://realpython.com/videos/write-python-script/#t=449.52 |
| 07:35 | https://realpython.com/videos/write-python-script/#t=455.6 |
| All right, | https://realpython.com/videos/write-python-script/#t=455.6 |
| you’ve made your first program. Next up, it’s time to make some mistakes. | https://realpython.com/videos/write-python-script/#t=456.08 |
| Sept. 29, 2023 | https://realpython.com/videos/write-python-script/#comment-ebba07e7-b52d-4162-8ab7-589f7a4e086e |
| Sept. 29, 2023 | https://realpython.com/videos/write-python-script/#comment-fbb9878c-50e1-45ac-8492-2e0429b427a2 |
| PythonAnywhere | https://www.pythonanywhere.com/ |
| GitHub Codespaces | https://github.com/features/codespaces |
| Sept. 29, 2023 | https://realpython.com/videos/write-python-script/#comment-ea7342cb-9b20-4ada-a0dd-de19efd1cbe4 |
| guide to IDEs and code editors | https://realpython.com/python-ides-code-editors-guide/ |
| covers an online coding environment | https://realpython.com/lessons/repl-it-overview-use-cases/ |
| March 10, 2024 | https://realpython.com/videos/write-python-script/#comment-e96e105b-177f-469b-812d-befbfcf9688a |
| March 10, 2024 | https://realpython.com/videos/write-python-script/#comment-b63846b5-764f-4171-b377-9f0117425a42 |
| changelog | https://docs.python.org/3/whatsnew/changelog.html#changelog |
| check out other editors | https://realpython.com/python-ides-code-editors-guide/ |
| July 4, 2024 | https://realpython.com/videos/write-python-script/#comment-ae768c4a-810c-4096-a295-ce1690f859b3 |
| July 4, 2024 | https://realpython.com/videos/write-python-script/#comment-0888c422-82ce-42da-be48-256d7833e571 |
| July 5, 2024 | https://realpython.com/videos/write-python-script/#comment-de9333b9-8bf0-4367-9d9d-704f5481e816 |
| July 8, 2024 | https://realpython.com/videos/write-python-script/#comment-89b70971-a038-4935-8c3c-b40272148393 |
| July 9, 2024 | https://realpython.com/videos/write-python-script/#comment-631d0cb7-9d75-463b-9e7a-185d3831630e |
| April 16, 2025 | https://realpython.com/videos/write-python-script/#comment-b6de81c4-9b86-4ea3-b5e8-aca5541d5889 |
| Become a Member | https://realpython.com/account/join/ |
| https://realpython.com/videos/first-python-program-overview/ |
| Overview | https://realpython.com/courses/python-basics-first-program/ |
| https://realpython.com/lessons/make-mistakes/ |
|
Code Your First Python Program (Overview) 01:39
| https://realpython.com/videos/first-python-program-overview/ |
|
Write a Python Script 07:41
| https://realpython.com/videos/write-python-script/ |
|
Make Some Mistakes 06:10
| https://realpython.com/lessons/make-mistakes/ |
|
Create and Inspect a Variable 12:51
| https://realpython.com/lessons/create-inspect-variable/ |
|
Leave Helpful Comments 04:06
| https://realpython.com/lessons/leave-helpful-comments/ |
|
Code Your First Python Program (Quiz) 09:30
| https://realpython.com/lessons/first-python-program-quiz/ |
|
Code Your First Python Program (Summary) 01:29
| https://realpython.com/lessons/first-python-program-summary/ |
| Privacy Policy | https://realpython.com/privacy-policy/ |
Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover