python安装教程这个可以解决99%的问题
1.1第一个代码 2快捷键查找: ctrl+f
全局查找:ctrl+shift+f
保存:ctrl+s
整块缩进:tab
取消缩进:shift+tab
注释/取消注释:ctrl+/
撤销:ctrl+z
3错误集中 3.1无法安装库将提示中的路径设置完全访问完美解决
4实例 4.1数据拟合import numpy as np
import matplotlib.pyplot as plt
x = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130]
y = [174, 216, 255, 290, 325, 361, 399, 433, 460, 480, 495, 500, 502]
x = np.array(x)
y = np.array(y)
plot = plt.plot(x, y, 'r*', label='original values')
fit = np.polyfit(x, y, 2) # 曲线的拟合 y=kx+b y=ax^2+bx+c
print(fit)
p1 = np.poly1d(fit) # 拟合的直线
print("拟合曲线:", p1)
yvals = p1(x)
plot2 = plt.plot(x, yvals, 'b', label='ploy fit values')
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False # 标题中文化
plt.xlabel('时间')
plt.ylabel('顾客数')
plt.title('数据拟合')
plt.legend()
plt.savefig('曲线拟合.png')
plt.show()
5字符串和数字
5.1字符串
被引号引起来的就是字符串
字符串的大小写、字符串的拼接、删除空白
myName = ' Zhang San '
print(myName.upper())
print(myName.title())
hisName = 'li si'
print('hello '+myName)
print('hello '+hisName)
print(myName.lstrip())
print(myName.rstrip()+'.')
print(myName.strip())
5.2数字
整数int和浮点数float
字符串和数字的转换
a = 9 b = '2' c = 2.0 print(a/int(b)) # 字符串转数字 print(a%c) print(str(a)+b) # 数字转字符串6列表
names = ['张三', '李四', '王五'] # 添加列表 print(names) # 访问列表 grades = [70, 92, 62, 87] # 数字列表不需要加引号 print(grades) # 输出整个列表 print(grades[0]) # 访问第一个元素 print(grades[-1]) # 访问最后一个元素 # 操作列表 grades[0] = 30 # 修改第一个元素 print(grades) grades.append(90) # 添加元素 print(grades) grades.insert(0, 20) # 在第一个位置插入20 print(grades) grades.pop(0) # 删除第一个元素 print(grades) grades.remove(90) # 删除某个特定元素 print(grades) print(len(grades)) # 取列表的长度 # 列表排序 grades.sort() # 永久排序 print(grades) print(sorted(grades)) # 临时排序 grades.reverse() # 反转列表 print(grades)7for循环
names = ['张三', '李四', '王五', '赵六']
for name in names:
print('hello,', name)
# for循环的另外一种形式
for index in range(len(names)):
print('hello!', names[index])
for index in range(2):
print('hello!', names[index])
print(range(2))
range(10)
range(0, 100, 10)
for num in range(10):
print(num)
for num in range(10, 100, 10):
print(num)
8While循环和跳出循环
num = 0
while (num<9):
num = num + 1 # 还可以写成 num += 1
if num % 2 == 0:
continue
print("num:", num)
print(num)



