Day2
学习内容
1.Python字符串操作(第二节);
2.数学极限学习;
随堂练习
import math
import time
import turtle
'''
MAX_SPEED = 20
a,b,c = 2,4,7
a,b = b,a
print(a,b)
d = c/b
e = c//b
f = c%b
g = b**2
h = divmod(10, 5) #同时得到商和余数,整数 3.14可写为314e-2
print(d, e, f, g, h)
print(round(3.14)) #四舍五入(不改变原有值,产生新的值)
print(time.time())
'''
'''
# 定义多个点的坐标
x1, y1 = 100, 100
x2, y2 = 100, -100
x3, y3 = -100, -100
x4, y4 = -100, 100
# 绘制折线
t = turtle.Pen()
t.penup()
t.goto(x1, y1)
t.pendown()
t.goto(x4, y4)
# 计算距离
distance = math.sqrt((x1-x4)**2 + (y1-y4)**2)
t.write(distance)
'''
# is用来判断两个标识符是不是引用同一个对象;is not 是判断两个标识符是不是引用不同对象,判断的是对象地址;
# python默认缓存[-5,256],在pycharm中则是[-5,+];
# 转义字符:\续行符,\\反斜杠符号,\'单引号,\"双引号,\b退格,\n换行,\t横向制表,\r回车
'''name = input("请输入姓名:")
print(name)
'''
# 可以通过str()函数将其余类型转为字符串,如str(3.14)-- ‘3.14’
# replace()可实现字符串替换
# 字符串切片slice,包头不包尾,步长为负则反向提取,标准格式为[起始偏移量start:终止偏移量end(end-1):步长step]
# 字符串倒序输出
'''
a = 'to be or not to be, this is a question'
b = ['sxt', 'sxt100', 'sxt200']
print(a[::-1])
# split()可对字符串进行分割
print(a.split("be"))
print(a)
print("*".join(b))
# 字符串的驻留机制,对于符合标识规则的字符串(仅包含下划线(_)、字母和数字)会启用字符串驻留机制
'''
'''
a = ''我是高琪,今年18岁了,我在北京尚学堂科技上班,我的儿子叫高洛希,他6岁了,我是一个编程教育的普及者,希望影响6000万学习编程的中国人,我儿子现在也开始学习编程,希望他18岁的时候能超过我''
print(len(a))
print(a.find('高')) # 正序查找,返回位置
print(a.rfind('高')) # 逆序查找,返回位置
print(a.startswith('我是高琪')) # 以什么开头
print(a.endswith('我')) # 以什么结尾
print(a.count("高")) # 计数
print(a.isalnum()) # 判断字符串是否只有数字和字母(isalpha()判断是否只由字母(汉字),isdigit()是否只由数字,isspace()是否只由空白,isupper()是否为大写,islower()是否为小写)
b = " **sx*t* "
print(b.strip()) # 两端去除空格
print(b.strip().strip('*')) # 去除两端指定字符
print(b.strip().rstrip('*')) # 逆序去除指定字符
c = 'to be or not to be, this is a question.'
print(c.capitalize()) # 产生新的字符串且首字母大写
print(c.title()) # 产生新的字符串,每个单词首字母都大写
print(c.upper()) # 产生新的字符串,每个字母都大写
print(c.lower()) # 产生新的字符串,每个字母都小写
print(c.swapcase()) # 产生新的字符串,每个字母大小写转换
d = 'sxt'
print(d.center(9, '#'))
print(d.ljust(9, '#'))
print(d.rjust(9, '#'))
'''
# format()格式化
a = "我的姓名是:{name},年龄:{age},目前工作单位是:{college}"
b = a.format(name='jeffery', age=25, college='SICAU')
print(b)
c = "我的姓名是:{name},年龄:{age:*^8},目前工作单位是:{college}" # ^,<,>分别代表居中,左对齐,右对齐
print(c.format(name='jeffery', age=25, college='SICAU'))