Python Programming Practice: Python Common Commands Quick Reference Sheet

amy 11/12/2025

During Python development, many commands and tool operations are easily forgotten. Whether you’re a beginner or an experienced developer, having a readily accessible “command cheatsheet” can significantly boost your efficiency.

This article summarizes commonly used commands for Python, pip, virtual environments, package management, file operations, debugging, formatting, performance testing, and code checking, serving as a comprehensive and essential memo for Python development.

You can bookmark this article or turn it into a single-page portable document.


1. Python Command Quick Reference

Basic Commands

PurposeCommand
Check Python versionpython --version / python3 --version
Enter interactive interpreterpython
Execute scriptpython script.py
Execute one line of codepython -c "print('hello')"
Run as modulepython -m http.server 8000

2. pip Package Management Commands

Basic Operations

ActionCommand
Check pip versionpip --version
Install packagepip install package_name
Install specific versionpip install package==1.2.3
Upgrade packagepip install --upgrade package
Uninstall packagepip uninstall package
List installed packagespip list
List outdated packagespip list --outdated

Export/Install Dependency List

FunctionCommand
Export dependenciespip freeze > requirements.txt
Install dependenciespip install -r requirements.txt

Domestic Mirrors (Speed Boost)

Mirror SourceExample
Tsinghua Universitypip install package -i https://pypi.tuna.tsinghua.edu.cn/simple

3. Virtual Environment Commands (venv)

Create Virtual Environment

bash

python -m venv venv

Activate Virtual Environment

SystemCommand
Windowsvenv\Scripts\activate
macOS/Linuxsource venv/bin/activate

Deactivate Virtual Environment

bash

deactivate

4. Poetry Commands (Modern Dependency Management)

Initialize Project

bash

poetry init

Install All Dependencies

bash

poetry install

Install a Dependency Package

bash

poetry add requests

Enter Virtual Environment Shell

bash

poetry shell

5. Common Python Module Commands

(1) json Module

python

import json
json.dumps({"a": 1}, ensure_ascii=False)  # dict → JSON
json.loads('{"a": 1}')                    # JSON → dict

(2) os Module (File & System Operations)

FunctionCommand
Current directoryos.getcwd()
List filesos.listdir(path)
Check if file/directoryos.path.isfile() / os.path.isdir()
Create directoryos.makedirs(path, exist_ok=True)
Delete fileos.remove(file_path)

(3) shutil (File Copy & Move)

python

shutil.copy(src, dst)
shutil.move(src, dst)
shutil.rmtree(folder)

6. requests Common Syntax Quick Reference

python

import requests

# GET
requests.get(url)

# POST
requests.post(url, data={"a": 1})

# JSON
requests.post(url, json={"key": "value"})

# Add headers
requests.get(url, headers={"User-Agent": "Mozilla"})

# Download file
requests.get(url).content

7. BeautifulSoup Common Commands

python

from bs4 import BeautifulSoup

soup = BeautifulSoup(html, "lxml")

soup.title.text
soup.find("div")
soup.find_all("a")
soup.select("div.classname")

8. Pandas Common Commands

Read Files

python

pd.read_csv("a.csv")
pd.read_excel("a.xlsx")

Common Operations

python

df.head()
df.info()
df.describe()
df.to_excel("out.xlsx", index=False)

9. Numpy Common Commands

python

np.array([...])
np.zeros((3,3))
np.ones((2,4))
np.random.rand(5)

10. Debugging (pdb)

python

import pdb; pdb.set_trace()

Common Debugging Commands:

CommandMeaning
nNext line
cContinue execution
p variablePrint variable
qQuit debugging

11. Logging Common Configuration

python

import logging
logging.basicConfig(level=logging.INFO)
logging.info("info msg")
logging.error("error msg")

12. Performance Testing Commands (timeit)

In Command Line:

bash

python -m timeit "x=5; x*x"

In Code:

python

import timeit
timeit.timeit("x=5; x*x")

13. Code Quality Checking

flake8 (Static Analysis)

bash

flake8 your_code.py

black (Code Formatter)

bash

black .

14. Packaging & Distribution

PyInstaller Packaging

bash

pyinstaller -F script.py

Build pip Package

bash

python setup.py sdist bdist_wheel
twine upload dist/*

15. Other Useful Commands Collection

Check Module Installation Location

bash

python -m site

Find Module Path

python

import module; print(module.__file__)

List All .py Files in Current Directory

bash

ls *.py

Conclusion

This cheatsheet covers the most commonly used commands, tools, and library operations in Python practice, spanning multiple areas: environment setup, package management, routine coding, performance debugging, formatting, packaging, and more.

Whether you’re writing scripts, performing data analysis, building web scrapers, developing backend APIs, or creating automation tools, these commands can save you a tremendous amount of time.