一、Python基本语法元素
- 缩进、注释、命名、变量、保留字
- 数据类型、字符串、 整数、浮点数、列表
- 赋值语句、分支语句、函数
- input()、print()、eval()、 print()格式化
1.1 温度转换
# TempConvert.py
TempStr = input("请输入带有符号的温度值: ")
if TempStr[-1] in ['F', 'f']:
C = (eval(TempStr[0:-1]) - 32) / 1.8
print("转换后的温度是{:.2f}C".format(C))
elif TempStr[-1] in ['C', 'c']:
F = 1.8 * eval(TempStr[0:-1]) + 32
print("转换后的温度是{:.2f}F".format(F))
else:
print("输入格式错误")
1.2 保留字
![008-Python基本语法元素小结-01.jpg?x-oss-process=style/watermark](http://www.chenyoude.com/%E9%A2%84%E7%A7%91%E7%8F%AD/008-Python%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95%E5%85%83%E7%B4%A0%E5%B0%8F%E7%BB%93-01.jpg?x-oss-process=style/watermark)
1.3 Python基本图形绘制
- 从计算机技术演进角度看待Python语言
- 海龟绘图体系及import保留字用法
- penup()、pendown()、pensize()、pencolor()
- fd()、circle()、seth()
- 循环语句:for和in、range()函数
1.4 Python蟒蛇绘制
import turtle
turtle.setup(650, 350, 200, 200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor("purple")
turtle.seth(-40)
for i in range(4):
turtle.circle(40, 80)
turtle.circle(-40, 80)
turtle.circle(40, 80 / 2)
turtle.fd(40)
turtle.circle(16, 180)
turtle.fd(40 * 2 / 3)
turtle.done()
![014-Python基本图形绘制小结-01.jpg?x-oss-process=style/watermark](http://www.chenyoude.com/%E9%A2%84%E7%A7%91%E7%8F%AD/014-Python%E5%9F%BA%E6%9C%AC%E5%9B%BE%E5%BD%A2%E7%BB%98%E5%88%B6%E5%B0%8F%E7%BB%93-01.jpg?x-oss-process=style/watermark)
二、基本数据类型
- 数据类型:整数、浮点数、复数及
- 数据类型运算操作符、运算函数
- 字符串类型:表示、索引、切片
- 字符串操作符、处理函数、处理方法、.format()格式化
- time库:time()、strftime()、strptime()、sleep()等