环境配置
Python解释器安装
IDE安装(Pycharm)
Typora安装
- markdown语法
正课内容
1. Python的历史即概括
(1)Python的出生和应用
吉多·范罗苏姆 Web开发、图像处理、数据分析
(2)Python的语言类型
- 动态
-
静态
-
-
编译型
-
解释型
-
强类型定义语言
-
弱类型定义语言
Python是一种解释型、动态类型、强类型计算机程序设计语言
(3)优缺点
(4)Python的种类
Cpython、Jyhton、PyPy、IronPython…
-
2. Python基础
2.1 第一条编程语句
print("hello,python!")
print("I love you ,charon!")
2.2 print()函数
作用:在控制台打印信息;
>>> help(print)
Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
2.3 注释
-
单行注释
-
一个“#”
# 这是单行注释
-
-
多行注释
-
三单引号
-
三双引号
‘’’
多行注释1
‘’’“”"
多行注释2
“”"print(“Hello, Python!”) # 第一条Python程序,向Python致敬!
print(“I love you ,charon!”)
‘’’
冥王星与卡戎的爱情永存!
‘’’
-
2.4 input()函数
作用:从外部获取值
用法:括号中可以提供提示信息
返回值为字符串类型
>>> a = input()
冥王星
>>> a
'冥王星'
>>> a = input("冥王星的卫星:")
冥王星的卫星:卡戎
>>> a
'卡戎'
>>>
2.5 运行Python程序的三种方式
(1) 解释器环境运行
(2) 脚本运行
(3) IDE
- pycharm
- sublime
- VS Code
- Atom
2.6 Python中常见的数据类型
数据的概念
python中的数据类型
-
数字(number)
- 整形(int)
- 浮点型(float)
- 布尔型(bool)
- 复数(complex)
-
字符串(string)
-
列表(list)
-
元组(tuple)
-
字典(dict)
-
集合(set)
2.7 变量和常量
变量
-
概念:
-
程序可操作的存储区的名称
-
程序运行时存储区中能够改变的数据
每个变量都有自己的特定的数据类型
-
-
作用:
- 将数据存储到内存
-
变量的定义
- 命名
规则:
-
必须是字母、下划线、数字组合
-
不能以数字开头
-
不可以是Python中的关键字
注意:
-
见名知意
-
区分大小写
-
在Python中,单下划线和双下划綫开头的变量有特殊的通途,一般不推荐使用单下划线和双下划綫开头的变量名称
-
-
变量定义
val_name = 初始值
关键词查看
>>> import keyword >>> keyword.kwlist ['False', 'None', 'True', 'and', 'as'