Master Python Basics in 9 Minutes: From Hello World to Modules
This concise tutorial walks you through essential Python fundamentals—including writing and running your first script, handling international character sets, using the interactive calculator, working with strings, lists, control flow, functions, file I/O, exception handling, classes, inheritance, and the package system—empowering beginners to start coding quickly.
1. Hello World
After installing Python, open IDLE (Python GUI), which is the interpreter where your statements run immediately. Type the classic hello‑world statement and press Enter to see the famous K&R introduction to programming.
Open a new editor window (File → New Window or Ctrl+N), write the following code, save it as a.py, and press F5 to run it. You can also double‑click the saved a.py file to see the result. Running Python scripts directly is an advantage over Java.
2. Internationalization Support
Create a new editor and write code that prints a greeting in a different language. When you save the file, Python may prompt you to change the file’s character set; select a more familiar encoding and the program runs correctly.
3. Convenient Calculator
Instead of using the cumbersome Windows calculator, you can perform calculations directly in the Python interpreter.
4. Strings, ASCII and UNICODE
Python can print predefined formatted strings. The tutorial shows how to access strings and highlights the differences between ASCII and UNICODE strings.
5. Using Lists
Python’s list type provides a convenient, easy‑to‑use data structure similar to Java’s List.
6. Conditional and Loop Statements
Examples of Python’s conditional statements and loops are presented.
7. Defining Functions
The tutorial introduces a handy function definition example.
8. File I/O
Basic file input/output operations are demonstrated.
9. Exception Handling
How to catch and handle exceptions in Python is explained.
10. Classes and Inheritance
Fundamental concepts of defining classes and using inheritance are covered.
11. Package Mechanism
Each .py file is a module; modules can import each other. A package is created by placing an __init__.py file (which can be empty) in each directory. The tutorial shows the directory structure, how Python discovers modules via sys.path, and ways to modify the module search path manually or via the PYTHONPATH environment variable.
12. Summary
The tutorial emphasizes that Python’s syntax is simple and its standard library is extensive, allowing programmers to quickly start coding without explicit type declarations. By mastering these basics, a programmer can transition from batch scripts to Python efficiently.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
