python基础语法
一、计算机组成原理
1.什么是计算机?
2.计算机是由什么组成的?
一个完整的计算机系统,是由硬件系统和软件系统两大部分组成的。
3.硬件系统
4. 软件系统
5.计算机是如何处理程序的?
6.编程语言是什么?
7.什么是Python?
Python就是一门编程语言,而且是现在世界上最流行的编程语言之一。
二、python简介
1.Python介绍
Python发展历史:链接
2.Python版本
3.总结
三、python解释器
1.解释器的作用
2.下载Python解释器
下载地址:https://www.python.org/downloads/release/python-372/
3.安装Python解释器
4.总结
四、注释
1.注释的作用
2.注释的分类及语法
3.快速体验
注意:解释器不执行任何的注释内容。
print('hello world')
print('hello Python')
"""
第一行注释
第二行注释
第三行注释
"""
'''
注释1
注释2=
注释3
'''
4.总结
五、变量
1.变量的作用
2.定义变量
标识符
命名习惯
使用变量
"""
1. 定义变量
语法:变量名 = 值
2. 使用变量
3. 看变量的特点
"""
my_name
= 'TOM'
print(my_name
)
schoolName
= '我是黑马程序员,我爱Python'
print(schoolName
)
认识bug
my_name
= 'TOM'
print(my_name
)
schoolName
= '我是黑马程序员,我爱Python'
print(schoolName
)
3.Debug工具
打断点
Debug调试
Debug输出面板分类
4.认识数据类型
"""
1. 按经验将不同的变量存储不同的类型的数据
2. 验证这些数据到底是什么类型 -- 检测数据类型 -- type(数据)
"""
num1
= 1
num2
= 1.1
print(type(num1
))
print(type(num2
))
a
= 'hello world'
print(type(a
))
b
= True
print(type(b
))
c
= [10, 20, 30]
print(type(c
))
d
= (10, 20, 30)
print(type(d
))
e
= {10, 20, 30}
print(type(e
))
f
= {'name': 'TOM', 'age': 18}
print(type(f
))
检测数据类型的方法:type()
"""
1. 按经验将不同的变量存储不同的类型的数据
2. 验证这些数据到底是什么类型 -- 检测数据类型 -- type(数据)
"""
num1
= 1
num2
= 1.1
print(type(num1
))
print(type(num2
))
a
= 'hello world'
print(type(a
))
b
= True
print(type(b
))
c
= [10, 20, 30]
print(type(c
))
d
= (10, 20, 30)
print(type(d
))
e
= {10, 20, 30}
print(type(e
))
f
= {'name': 'TOM', 'age': 18}
print(type(f
))
5.总结
六、输出
1.格式化输出
所谓的格式化输出即按照一定的格式输出内容。
格式化符号
"""
1. 准备数据
2. 格式化符号输出数据
"""
age
= 18
name
= 'TOM'
weight
= 75.5
stu_id
= 1
stu_id2
= 1000
print('今年我的年龄是%d岁' % age
)
print('我的名字是%s' % name
)
print('我的体重是%.3f公斤' % weight
)
print('我的学号是%d' % stu_id
)
print('我的学号是%03d' % stu_id
)
print('我的学号是%03d' % stu_id2
)
print('我的名字是%s,今年%d岁了' % (name
, age
))
print('我的名字是%s,明年%d岁了' % (name
, age
+ 1))
print('我的名字是%s,今年%d岁了,体重%.2f公斤,学号是%06d' % (name
, age
, weight
, stu_id
))
2.体验
格式化字符串除了%s,还可以写为f’{表达式}’ f-格式化字符串是Python3.6中新增的格式化方法,该方法更简单易读。
name
= 'TOM'
age
= 18
weight
= 75.5
print('我的名字是%s,今年%s岁了,体重%s公斤' % (name
, age
, weight
))
name
= 'TOM'
age
= 18
print('我的名字是%s,今年%s岁了' % (name
, age
))
print(f
'我的名字是{name},今年{age}岁了')
3.转义字符
print('hello')
print('world')
print('hello\nPython')
print('\tabcd')
4.结束符
print('hello', end
="\n")
print('world', end
="\t")
print('hello', end
="...")
print('Python')
5.总结
七、 输入
1.输入的语法
"""
1. 书写input
input('提示信息')
2. 观察特点
2.1 遇到input,等待用户输入
2.2 接收input存变量
2.3 input接收到的数据类型都是字符串
"""
password
= input('请输入您的密码:')
print(f
'您输入的密码是{password}')
print(type(password
))
2.输入的特点
3.总结
八、数据类型转换
1.转换数据类型的作用
2.转换数据类型的函数
3.快速体验
"""
1. input
2. 检测input数据类型str
3. int() 转换数据类型
4. 检测是否转换成功
"""
num
= input('请输入数字:')
print(num
)
print(type(num
))
print(type(int(num
)))
4.实验
num1
= 1
str1
= '10'
print(type(float(num1
)))
print(float(num1
))
print(float(str1
))
print(type(str(num1
)))
list1
= [10, 20, 30]
print(tuple(list1
))
t1
= (100, 200, 300)
print(list(t1
))
str2
= '1'
str3
= '1.1'
str4
= '(1000, 2000, 3000)'
str5
= '[1000, 2000, 3000]'
print(type(eval(str2
)))
print(type(eval(str3
)))
print(type(eval(str4
)))
print(type(eval(str5
)))
5.总结
九、运算符
1.算数运算符
2.赋值运算符
3.复合赋值运算符
a
= 10
a
+= 1
print(a
)
b
= 10
b
-= 1
print(b
)
c
= 10
c
+= 1 + 2
print(c
)
d
= 10
d
*= 1 + 2
print(d
)
4.比较运算符
5.逻辑运算符
a
= 0
b
= 1
c
= 2
print((a
< b
) and (c
> b
))
print(a
> b
and c
> b
)
print(a
< b
or c
> b
)
print(a
> b
or c
> b
)
print(not False)
print(not c
> b
)
拓展
6. 总结