Get started using Python on Windows for beginners

The following is a step-past-stride guide for beginners interested in learning Python using Windows.

Set your development environment

For beginners who are new to Python, nosotros recommend y'all install Python from the Microsoft Store. Installing via the Microsoft Shop uses the basic Python3 interpreter, only handles prepare of your PATH settings for the current user (avoiding the need for admin access), in addition to providing automatic updates. This is particularly helpful if you lot are in an educational environment or a function of an organization that restricts permissions or authoritative access on your machine.

If you are using Python on Windows for web development, we recommend a different ready for your development environment. Rather than installing directly on Windows, we recommend installing and using Python via the Windows Subsystem for Linux. For assistance, run across: Become started using Python for web development on Windows. If you lot're interested in automating common tasks on your operating system, run into our guide: Become started using Python on Windows for scripting and automation. For some advanced scenarios (like needing to access/modify Python's installed files, make copies of binaries, or use Python DLLs directly), you may want to consider downloading a specific Python release directly from python.org or consider installing an alternative, such equally Anaconda, Jython, PyPy, WinPython, IronPython, etc. Nosotros just recommend this if y'all are a more avant-garde Python programmer with a specific reason for choosing an alternative implementation.

Install Python

To install Python using the Microsoft Store:

  1. Go to your Start bill of fare (lower left Windows icon), type "Microsoft Store", select the link to open the store.

  2. One time the store is open, select Search from the upper-correct menu and enter "Python". Select which version of Python you lot would similar to use from the results under Apps. Nosotros recommend using the most recent unless yous take a reason not to (such as aligning with the version used on a pre-existing projection that y'all program to piece of work on). One time you've determined which version you would like to install, select Get.

  3. Once Python has completed the downloading and installation procedure, open Windows PowerShell using the Start menu (lower left Windows icon). Once PowerShell is open, enter Python --version to confirm that Python3 has installed on your automobile.

  4. The Microsoft Shop installation of Python includes pip, the standard package manager. Pip allows you to install and manage additional packages that are non part of the Python standard library. To confirm that y'all also have pip bachelor to install and manage packages, enter pip --version.

Install Visual Studio Code

By using VS Code every bit your text editor / integrated development environment (IDE), you can have advantage of IntelliSense (a code completion aid), Linting (helps avoid making errors in your lawmaking), Debug support (helps you find errors in your code after you run it), Code snippets (templates for small reusable code blocks), and Unit testing (testing your lawmaking'due south interface with unlike types of input).

VS Code also contains a built-in concluding that enables you to open a Python control line with Windows Command prompt, PowerShell, or whatever you prefer, establishing a seamless workflow betwixt your lawmaking editor and command line.

  1. To install VS Code, download VS Code for Windows: https://lawmaking.visualstudio.com.

  2. Once VS Lawmaking has been installed, you must as well install the Python extension. To install the Python extension, you tin can select the VS Code Market link or open VS Code and search for Python in the extensions bill of fare (Ctrl+Shift+10).

  3. Python is an interpreted language, and in order to run Python lawmaking, yous must tell VS Code which interpreter to utilize. We recommend using the most recent version of Python unless you have a specific reason for choosing something unlike. Once y'all've installed the Python extension, select a Python 3 interpreter by opening the Control Palette (Ctrl+Shift+P), start typing the command Python: Select Interpreter to search, then select the command. You lot can too use the Select Python Environment selection on the bottom Status Bar if available (it may already bear witness a selected interpreter). The command presents a list of available interpreters that VS Code can find automatically, including virtual environments. If you lot don't run into the desired interpreter, run into Configuring Python environments.

    Select Python interpreter in VS Code

  4. To open the terminal in VS Code, select View > Last, or alternatively use the shortcut Ctrl+` (using the backtick character). The default last is PowerShell.

  5. Within your VS Lawmaking last, open Python by merely inbound the command: python

  6. Effort the Python interpreter out by inbound: impress("Hullo Earth"). Python will return your statement "Hullo Earth".

    Python command line in VS Code

Install Git (optional)

If you plan to interact with others on your Python code, or host your projection on an open up-source site (similar GitHub), VS Code supports version control with Git. The Source Command tab in VS Code tracks all of your changes and has mutual Git commands (add together, commit, push, pull) built right into the UI. You first need to install Git to power the Source Command console.

  1. Download and install Git for Windows from the git-scm website.

  2. An Install Wizard is included that volition inquire you a series of questions about settings for your Git installation. We recommend using all of the default settings, unless you have a specific reason for changing something.

  3. If you lot've never worked with Git earlier, GitHub Guides tin can help y'all go started.

Howdy Globe tutorial for some Python basics

Python, according to its creator Guido van Rossum, is a "high-level programming language, and its core design philosophy is all about code readability and a syntax which allows programmers to express concepts in a few lines of code."

Python is an interpreted language. In dissimilarity to compiled languages, in which the code you write needs to be translated into auto code in order to be run by your calculator'due south processor, Python code is passed direct to an interpreter and run directly. Y'all just type in your code and run information technology. Let'due south try information technology!

  1. With your PowerShell command line open, enter python to run the Python iii interpreter. (Some instructions adopt to use the control py or python3, these should also work). Y'all will know that you're successful because a >>> prompt with three greater-than symbols volition display.

  2. At that place are several born methods that let you to make modifications to strings in Python. Create a variable, with: variable = 'Hello World!'. Press Enter for a new line.

  3. Print your variable with: print(variable). This will brandish the text "Howdy World!".

  4. Find out the length, how many characters are used, of your string variable with: len(variable). This will display that there are 12 characters used. (Annotation that the blank space it counted as a grapheme in the total length.)

  5. Convert your string variable to upper-case messages: variable.upper(). Now convert your string variable to lower-case letters: variable.lower().

  6. Count how many times the letter "l" is used in your string variable: variable.count("l").

  7. Search for a specific character in your string variable, let'south notice the assertion bespeak, with: variable.discover("!"). This will display that the assertion point is found in the 11th position character of the cord.

  8. Supercede the exclamation point with a question mark: variable.supervene upon("!", "?").

  9. To exit Python, you tin can enter go out(), quit(), or select Ctrl-Z.

PowerShell screenshot of this tutorial

Hope you had fun using some of Python's built-in cord modification methods. At present try creating a Python program file and running information technology with VS Lawmaking.

Hello Globe tutorial for using Python with VS Code

The VS Code squad has put together a peachy Getting Started with Python tutorial walking through how to create a Hello Globe programme with Python, run the program file, configure and run the debugger, and install packages like matplotlib and numpy to create a graphical plot inside a virtual environment.

  1. Open PowerShell and create an empty folder called "howdy", navigate into this folder, and open it in VS Code:

                      mkdir hello cd howdy lawmaking .                                  
  2. In one case VS Code opens, displaying your new hello folder in the left-side Explorer window, open a command line window in the lesser panel of VS Code by pressing Ctrl+` (using the backtick character) or selecting View > Terminal. Past starting VS Code in a folder, that folder becomes your "workspace". VS Lawmaking stores settings that are specific to that workspace in .vscode/settings.json, which are dissever from user settings that are stored globally.

  3. Continue the tutorial in the VS Code docs: Create a Python Hello Globe source code file.

Create a simple game with Pygame

Pygame running a sample game

Pygame is a popular Python package for writing games - encouraging students to learn programming while creating something fun. Pygame displays graphics in a new window, and so it will non work under the command-line-but arroyo of WSL. Notwithstanding, if you lot installed Python via the Microsoft Store as detailed in this tutorial, it will piece of work fine.

  1. Once you lot accept Python installed, install pygame from the command line (or the terminal from within VS Lawmaking) past typing python -m pip install -U pygame --user.

  2. Test the installation by running a sample game : python -g pygame.examples.aliens

  3. All being well, the game volition open a window. Close the window when yous are done playing.

Here'south how to start writing your own game.

  1. Open up PowerShell (or Windows Command Prompt) and create an empty binder chosen "bounce". Navigate to this folder and create a file named "bounce.py". Open the folder in VS Code:

                      mkdir bounce cd bounce new-item bounce.py code .                                  
  2. Using VS Code, enter the following Python code (or copy and paste it):

                      import sys, pygame  pygame.init()  size = width, height = 640, 480 dx = 1 dy = 1 x= 163 y = 120 black = (0,0,0) white = (255,255,255)  screen = pygame.display.set_mode(size)  while 1:      for event in pygame.event.get():         if event.type == pygame.QUIT: sys.get out()      x += dx     y += dy      if x < 0 or x > width:            dx = -dx      if y < 0 or y > acme:         dy = -dy      screen.make full(blackness)      pygame.draw.circle(screen, white, (x,y), 8)      pygame.display.flip()                                  
  3. Salve it as: bounce.py.

  4. From the PowerShell terminal, run it by entering: python bounce.py.

    Pygame running the next big thing

Try adjusting some of the numbers to meet what outcome they accept on your billowy brawl.

Read more about writing games with pygame at pygame.org.

Resources for continued learning

We recommend the following resources to back up y'all in continuing to learn about Python development on Windows.

Online courses for learning Python

  • Introduction to Python on Microsoft Larn: Try the interactive Microsoft Larn platform and earn experience points for completing this module covering the basics on how to write basic Python code, declare variables, and work with console input and output. The interactive sandbox environment makes this a great place to start for folks who don't accept their Python development environs set upwardly yet.

  • Python on Pluralsight: 8 Courses, 29 Hours: The Python learning path on Pluralsight offers online courses covering a diversity of topics related to Python, including a tool to mensurate your skill and discover your gaps.

  • LearnPython.org Tutorials: Go started on learning Python without needing to install or set anything up with these free interactive Python tutorials from the folks at DataCamp.

  • The Python.org Tutorials: Introduces the reader informally to the bones concepts and features of the Python language and system.

  • Learning Python on Lynda.com: A basic introduction to Python.

Working with Python in VS Code

  • Editing Python in VS Lawmaking: Acquire more about how to take advantage of VS Code's autocomplete and IntelliSense support for Python, including how to customize their beliefs... or just turn them off.

  • Linting Python: Linting is the procedure of running a programme that will analyse code for potential errors. Learn about the different forms of linting back up VS Code provides for Python and how to gear up it up.

  • Debugging Python: Debugging is the process of identifying and removing errors from a computer program. This article covers how to initialize and configure debugging for Python with VS Code, how to set and validate breakpoints, attach a local script, perform debugging for different app types or on a remote computer, and some basic troubleshooting.

  • Unit testing Python: Covers some background explaining what unit testing means, an example walkthrough, enabling a test framework, creating and running your tests, debugging tests, and test configuration settings.