What are the best commands in Python

Getting started using Python on Windows for beginners

  • 10 minutes to read

The following detailed instructions are aimed at beginners who want to familiarize themselves with Python under Windows 10.

Setting up the development environment

For beginners who are not yet familiar with Python, it is recommended to install Python via the Microsoft Store. When installing from the Microsoft Store, the basic Python3 interpreter is used, but in addition to providing automatic updates, your PATH settings are set up for the current user (so no administrator access is required). This is especially useful if you are in a training environment or in an organization that is restricting permissions or administrative access to your computer.

If you're using Python on Windows for Web development a different setup is recommended for your development environment. Instead of installing directly on Windows, we recommend installing and using Python via the Windows subsystem for Linux. For help, see: Getting started using Python for web development on Windows. If you want to automate common tasks in the operating system, check out our Getting Started Using Python on Windows for Scripting and Automation guide. For some advanced scenarios (such as when you need to access or modify installed Python files, make copies of binary files, or build Python DLLs directly), consider a specific Python release directly from python.org download or install an alternative, e.g. B. Anaconda, Jython, PyPy, WinPython, IronPython, etc. This is only recommended if you are an accomplished Python programmer and you have specific reasons for choosing an alternative implementation.

Install Python

To install Python using the Microsoft Store:

  1. Go to the menu begin (lower left Windows icon), enter “Microsoft Store” and select the link to open the store.

  2. Once the store is open, select in the top right menu Search and enter “python”. From the results under Apps, choose which version of Python you want to use. We recommend using the latest version, unless there is a reason not to do this (e.g. comparison with the version used in an existing project that you want to work on). After you have determined which version you want to install, choose Recall out.

  3. After Python completes the download and installation process, open Windows PowerShell from the menu begin (lower left Windows symbol). With PowerShell open, enter to confirm that Python 3 has been installed on your computer.

  4. The Microsoft Store installation of Python includes PIP, the default package manager. PIP allows you to install and manage additional packages that are not part of the standard Python library. Enter to confirm that you also have PIP available to install and manage packages.

Install Visual Studio Code

When using VS Code as a text editor / Integrated Development Environment (IDE), you can use IntelliSense (a code completion aid), Linting (helps avoid bugs in your code), Debug Assistance (helps you spot bugs in your code execution), code snippets (templates for small reusable code blocks) and unit tests (testing the code interface with different input types).

VS Code also includes a built-in terminal that lets you open a Python command line using the Windows Command Prompt, PowerShell, or any other tool of your choice. This establishes a seamless workflow between the code editor and the command line.

  1. If you want to install VS Code, download the tool for Windows: https://code.visualstudio.com.

  2. After VS Code is installed, you will also need to install the Python extension. To install the Python extension, you can select the VS Code Marketplace link or open VS Code and search for. In the extension menu (CTRL + SHIFT + X) python search.

  3. Python is an interpreted language, and in order to run Python code, you need to tell VS Code which interpreter to use. We recommend using the latest version of Python unless you have a specific reason to choose. After installing the Python extension, choose a Python 3 interpreter by using the Command palette Open (CTRL + SHIFT + P) and enter the command Python: Select Interpreter to search for and select the command. You can also choose the option Select Python Environment Use (Select Python Environment) on the lower status bar (a selected interpreter may already be displayed there). The command displays a list of available interpreters that VS Code can automatically find, including virtual environments. If you don't see the interpreter you want, see Configuring Python Environments.

  4. To open the terminal in VS Code, select Show > terminal or alternatively use the keyboard shortcut CTRL + ` (with the grave accent). The standard terminal is PowerShell.

  5. Open Python in your VS Code terminal by typing the command.

  6. Try the Python interpreter by typing:. Python returns your "Hello World" statement.

Install Git (optional)

If you intend to collaborate on your Python code with others or to host the project in an open source location (like GitHub), VS Code supports version control with Git. The Source Control tab in VS Code will list all Changes tracked and common Git commands ("Add", "Commit", "Push", "Pull") integrated directly into the user interface. You must first install Git to enable the Source Control section.

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

  2. An installation wizard is included that asks you a series of questions about the settings for the Git installation. You should use all of the default settings unless you have a specific reason to change something.

  3. If you've never used Git before, you can use GitHub guides to get started.

Hello World tutorial for some Python basics

According to the inventor Guido van Rossum, Python is a "high-level programming language with the readability of code as the central design philosophy and a syntax that enables programmers to express concepts in a few lines of code".

Python is an interpreted programming language. Unlike compiled languages, in which the code written must be translated into computer code in order to be executed by the computer's processor, Python code is passed directly to an interpreter and executed. You just enter your code and run it. Try it!

  1. With the PowerShell command line open, type to run the Python 3 interpreter. (Some guides prefer to use the or command, which should work as well.) You know you've succeeded because the prompt displays “>>>” (three greater-than symbols).

  2. There are several built-in methods you can use to make changes to strings in Python. Create a variable with. Press Enter to start a new line.

  3. Print out your variable with. This will display the text “Hello World!”.

  4. Find out the length of your string variable (the number of characters used) with. This indicates that 12 characters are used. (Note that the space is included in the total length.)

  5. Convert the string variable to uppercase:. Now convert the string variable to lowercase:.

  6. Count the number of times the letter “l” appears in the string variable:.

  7. In the string variable, look for a specific character - the exclamation point:. This indicates that the exclamation point is 11th in the string.

  8. Replace the exclamation mark with a question mark:.

  9. To quit Python, you can type, or "CTRL + Z".

We hope you enjoyed some of Python's built-in methods for changing strings. Now try creating a Python executable and running it using VS Code.

Hello World tutorial on using Python with VS Code

The VS Code team created an excellent Getting Started with Python tutorial that you can take by creating a "hello world" program with Python, running the executable, configuring the debugger, and installing packages like matplotlib and numpy leads. With these packages you can create graphical representations in a virtual environment.

  1. Open PowerShell and create an empty folder named "hello". Navigate to this folder and open it in VS Code:

  2. After opening VS Code, the new folder will be Hello in the left ExplorerWindow is displayed. At the bottom of VS Code, open a command line window by pressing CTRL + ` Press (grave accent) or view > terminal choose. When you start VS Code in a folder, that folder automatically becomes your “workspace”. VS Code saves the specific settings for this workspace, which do not belong to the globally saved user settings, in the file ".vscode / settings.json".

  3. Continue with the tutorial in the VS Code documentation: Create a Python Hello World source code file.

Create a simple game with pygame

Pygame is a popular Python game development package that is designed to teach students how to code in a fun way. Pygame displays graphics in a new window. Because of this, it does not work when using the WSL method on the command line. However, if you installed Python through the Microsoft Store as described in this tutorial, it will work fine.

  1. After installing Python, install pygame from the command line (or the terminal in VS Code) by typing.

  2. Test the installation by running a sample game:.

  3. If everything works, the game will open a window. Close the window when you've played enough.

Here's how to start creating your own game

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

  2. Using VS Code, type (or copy and paste) the following Python code:

  3. Save the file as:.

  4. Run the file on the PowerShell terminal by typing:.

Try adjusting some of the numbers to see what effect they have on the bouncing ball.

For more information on creating games with pygame, visit pygame.org.

Resources for further learning

We recommend the following resources to learn more about Python development on Windows.

Online courses to learn Python

  • Introducing Python on Microsoft Learn: Try the Microsoft Learn interactive platform and gain experience points for completing this module with the basics of writing simple Python code, declaring variables, and working with console input and output. The interactive sandbox environment is an ideal starting point for users who have not yet set up a Python development environment.

  • Python at Pluralsight: 8 courses, 29 hours: The Python Learning Path at Pluralsight offers online courses that cover a variety of topics related to Python, including a tool to measure your skills and find gaps.

  • Tutorials on LearnPython.org: Get started with Python without installing or setting up anything with these free interactive Python tutorials from the folks at DataCamp.

  • Tutorials on python.org: Here you will find an introduction to the basic concepts and features of the programming language and the Python system.

  • Learning Python on Lynda.com: A Basic Introduction to Python.

Working with Python in VS Code

  • Editing Python in VS Code: Learn more about how to take advantage of VS Code's AutoComplete and IntelliSense support for Python, including customizing the behavior - or how to just turn these features off.

  • Linting in Python: Linting is the process of running a program that analyzes your code for possible errors. Learn about the different forms of linting support in VS Code for Python and how to set up linting.

  • Debugging Python: Debugging is the process of detecting and removing errors from a computer program. This article describes how to initialize and configure debugging for Python using VS Code, how to set and check breakpoints, attach a local script, debug different types of apps or on a remote computer, and do some basic bug fixes.

  • Unit tests in Python: Use a walkthrough to learn some background about unit tests, how to enable a test framework, how to create and run tests, and how to debug tests, and test configuration settings.

Is this page helpful?