Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

A step-by-step guide on how to write and run your first Python program


Tutorial 1.3 - Introduction to Python


A step-by-step guide on how to write and run your first Python program using a simple text editor and the command line:

1. Install Python:

If you haven't already, download and install Python from the official Python website: https://www.python.org/downloads/

2. Open a Text Editor:

Open a simple text editor on your computer. You can use Notepad on Windows, TextEdit on macOS, or any other text editor of your choice.

3. Write Your Python Code:

Type the following code into the text editor:

print("Hello, Python!")

This code uses the print() function to display the text "Hello, Python!" on the screen.

4. Save the File:

Save the file with a .py extension. For example, you can save it as hello.py. Make sure to choose a location where you can easily find the file.

5. Open the Command Line or Terminal:

  • Windows: Press Win + R, type cmd, and press Enter.
  • macOS: Press Cmd + Space, type Terminal, and press Enter.

6. Navigate to the File Location:

Use the cd command to navigate to the directory where you saved your hello.py file. For example, if you saved it on your Desktop, you can use the following commands:

# On Windows cd Desktop # On macOS/Linux cd ~/Desktop

7. Run the Python Program:

In the command line or terminal, type the following command and press Enter:

python hello.py

If you're using Python 3, use the following command instead:

python3 hello.py


8. View the Output:

You should see the output of your program on the screen:

Hello, Python!


9. Congratulations!

You've successfully written and run your first Python program. You used the print() function to display a message on the screen. This simple example demonstrates the basic structure of a Python program and how to execute it using the command line or terminal.

As you continue learning Python, you'll explore more complex programming concepts, data manipulation, functions, and much more. Happy coding!



This post first appeared on Tsarde, please read the originial post: here

Share the post

A step-by-step guide on how to write and run your first Python program

×

Subscribe to Tsarde

Get updates delivered right to your inbox!

Thank you for your subscription

×