Python Introduction and Basic Syntax Overview
This article provides a comprehensive introduction to Python, covering its history, key features, basic syntax for running scripts, encoding declarations, identifier rules, keywords, operators, variable usage, core data types, string and bytes handling, input/output functions, and module import techniques.
Introduction
Python is a high‑level, interpreted, interactive, object‑oriented scripting language created by Guido van Rossum in 1989; the first public release appeared in 1991.
Key Features
Easy to learn with simple syntax and few keywords.
Readable code and maintainable source.
Extensive standard library that works across Unix, Windows and macOS.
Interactive mode, portable, extensible via C/C++, database interfaces, GUI support, embedding, and strong OOP.
Basic Syntax
Running Python
Enter the interactive interpreter with python and exit using exit() or Ctrl + D. Execute a script file with python script-file.py. A shebang line #!/usr/bin/env python allows direct execution of /path/to/script-file.py (Unix only).
Encoding
Source files are UTF‑8 by default. Explicit encoding can be declared as the first line, e.g. # -*- coding: utf-8 -*- or # encoding: utf-8.
Identifiers
Identifiers must start with a letter or underscore ( _) and may contain letters, digits, and underscores; they are case‑sensitive. Non‑ASCII identifiers are allowed from Python 3.x but discouraged.
Keywords
Keywords cannot be used as identifiers. The keyword module lists them, for example:
import keyword
keyword.kwlistwhich outputs ['False','None','True','and',...].
Operators
Python supports arithmetic, comparison, assignment, bitwise, logical, membership, and identity operators and follows standard precedence rules (parentheses can override).
Variables
Variables must be assigned before use; attempting to read an undefined name raises NameError.
Data Types
Core types include bool (True/False), int , float , complex , str , and bytes . Numeric operations follow Python’s rules (e.g., / always returns float, // performs floor division). Strings are immutable, support concatenation ( +) and repetition ( *), and can be defined with single, double, or triple quotes. Bytes are prefixed with b and require explicit encoding/decoding.
Input and Output
Use input() to read user input and print() for output; print(..., end="") suppresses the newline.
Import Statements
Modules can be imported with import module_name or specific objects with from module_name import name, and all symbols with from module_name import *.
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.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
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.
