Home > Backend Development > Python Tutorial > Quick Start with Python: Example Code Analysis

Quick Start with Python: Example Code Analysis

王林
Release: 2023-04-21 16:40:09
forward
1920 people have browsed it

Python installation

If you have already installed the software, if you want to check whether python has been installed on your Windows PC, please search for Python in the start bar or directly enter Python in the command prompt window and press Enter. If Once installed, your installation information will appear.

Quick Start with Python: Example Code Analysis

Quick Start with Python

Python is an interpreted programming language, which means that as a developer, you can write Python in a text editor ( .py) files, and then put these files into the python interpreter for execution.

The way to run a python file on the command line is as follows:

C:\Users\Your Name>python helloworld.py
Copy after login
Copy after login

where "helloworld.py" is the file name of python.

Let's write our first Python file called helloworld.py, which can be done in any text editor.

helloworld.py

print("Hello, World!")
Copy after login

Running the instance

Quick Start with Python: Example Code Analysis

It’s that simple. save document. Open a command line, navigate to the directory where you saved the file, and run:

C:\Users\Your Name>python helloworld.py
Copy after login
Copy after login

Output:

Hello, World!
Copy after login

Congratulations, you have written and executed your first Python program.

Python Command Line

To test a small amount of code in python, writing the code in a file is sometimes not the fastest and easiest. It is possible to run Python as a command line.

Type the following on the Windows, Mac or Linux command line:

C:\Users\Your Name>python
Copy after login

From here, you can write any python, including the previous hello world example:

C:\Users\Your Name>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, World!")
Copy after login

This will Output "Hello, World!" in the command line:

C:\Users\Your Name>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, World!")
Hello, World!
Copy after login

At any time, you can exit the python command line interface by typing the following command:

exit()
Copy after login

The above is the detailed content of Quick Start with Python: Example Code Analysis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template