Lesson 2: Python Getting Started


 Python Install

Many PCs and Macs come with Python pre-installed. To check if you have Python installed on your system, follow these steps:

Windows:

  1. Open the Command Line (cmd.exe).
  2. Type the following command and press Enter:

C:\Users\Your Name>python --version

Linux/Mac:

  1. Open the Command Line on Linux or the Terminal on Mac.
  2. Type the following command and press Enter:

python --version

If Python is installed, you will see the version number. If not, you can download and install Python for free from the official website: https://www.python.org/

Python QuickStart

Python is an interpreted programming language, which means that you write Python (.py) files in a text editor and then execute those files using the Python interpreter.

Running Python Files

To run a Python file from the command line, use the following syntax:

Windows:

C:\Users\Your Name>python filename.py

Linux/Mac:

python filename.py

Replace "filename.py" with the name of your Python file.

Writing Your First Python File

Let's create a simple Python file called "helloworld.py." Open your preferred text editor and enter the following code:

# helloworld.py

print("Hello, World!")

Save the file. Open your command line or terminal, navigate to the directory where you saved your file, and run the following command:

Windows:

C:\Users\Your Name>python helloworld.py

Linux/Mac:

python helloworld.py

You should see the following output:

Hello, World!

Congratulations! You've just executed your first Python program. This basic "Hello, World!" script serves as a simple introduction to the Python programming language. Feel free to explore and experiment with more advanced concepts as you continue your Python journey.

Post a Comment

0 Comments