Python Tutorials - Herong's Tutorial Examples - v2.14, by Herong Yang
Run Python Scripts on Linux
This section provides a tutorial example to verify Python environment supported on Linux computers and run a simple Python interactive scripting session.
Linux computers support Python out-of-the-box. You don't have to do any installation to run Python scripts. Here is what I tried on my macOS computer.
1. Start a Terminal window and try to run Python scripts interactively as shown below:
herong$ python --version Python 3.6.8 herong$ python Python 3.6.8 (default, Aug 24 2020, 17:57:11) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print "Hello world!\n" Hello world! >>> exit()
Note that you need to call the "exit()" function to terminate the Python interactive session.
2. If you just want to run one line of Python code, you can specify it in the command option "-c" as shown below:
herong$ python -c 'print "Hello world!\n"' Hello world!
3. If you have a Python script file, you can run it in non-interactive mode as command argument as shown below:
herong$ python hello.py Hello world!
Table of Contents
Install Python 2 Environment on CentOS
Variables, Operations and Expressions
Function Statement and Function Call
Iterators, Generators and List Comprehensions
Packages and Package Directories
"pathlib" - Object-Oriented Filesystem Paths
"pip" - Package Installer for Python
SciPy.org - Python Libraries for Science
pandas - Data Analysis and Manipulation
Anaconda - Python Environment Manager