前言
Python 作为当今最流行的编程语言之一,以其简洁的语法、强大的功能和丰富的生态系统赢得了全球开发者的青睐。无论你是想进入数据科学、Web 开发、自动化脚本还是人工智能领域,Python 都是绝佳的起点。本文将带你快速掌握 Python 的核心概念,助你开启编程之旅。
一、Python 环境搭建
1.1 安装 Python
访问 Python 官网下载最新稳定版本,推荐 Python 3.8+。
Windows 用户注意:安装时勾选 "Add Python to PATH" 选项。
1.2 验证安装
打开终端/命令行,输入:
python --version
或
python3 --version
应显示已安装的 Python 版本号。
1.3 选择开发工具
推荐初学者使用:
- IDLE(Python 自带)
- VS Code(轻量级且强大)
- PyCharm(专业 Python IDE)
二、Python 基础语法
2.1 第一个 Python 程序
创建一个 hello.py 文件,写入:
print("Hello, Python World!")
运行它:
python hello.py
2.2 变量与数据类型
# 基本数据类型
name = "Alice" # 字符串 (str)
age = 25 # 整数 (int)
price = 19.99 # 浮点数 (float)
is_student = True # 布尔值 (bool)
# 打印变量类型
print(type(name)) # <class 'str'>
print(type(age)) # <class 'int'>
2.3 基本运算
# 算术运算
print(10 + 3) # 13
print(10 - )
( * )
( / )
( // )
( % )
( ** )
( > )
( == )
( != )


