day11的作业
1
方法一:用cmd 给其软件和程序的地址,执行
方法二:用应用程序,如pycharm
2
8bit=1字节,
3
ASCII是英文码8位,
Unicode万国码
utf-8中文码
gbk
4
用utf-8用6位 gbk 用4位
5
# """ """
6
数字字母下划线,不能标已有的
从0开始的,而且查找时候不能超过最大的位置
7
用bit_length 3 101
8
True False
并且0,""是假的 其他数字和" "是真的
bool(a) 转换成布尔值
int()
9
alex
Alex
10
name[1:-1]
name[1:-2]
a
name=" aleX"
name=name.strip()
print(name)
b
name=" aleX"
name=name.startswith('al')
print(name)
c
name=" aleX"
name=name.endswith('x')
print(name)
d
name=' altX'
v=name.replace('l','p')
print(v)
e
name=' altX'
v=name.partition("l")
print(v)
f得到的列表类型
gh
name=' altX'
v=name.upper()
print(v)
i
name=' altX'
v=name[1]
print(v)
j
name=' altX'
i=0
for v in name :
if i<3:
print(v)
i+=1
k 不行???
name=' aleX'
index=0
for index < len(test)-2:
name[index]=' ' 难道是只能读出来,不能写入
name=name.lstrip()
l
name=' aleX'
v=name.find('e')
print(v)
21
暂时记 为可迭代对象
for i in 值:
print(i)
22
name=' aleX'
v='_'.join(name)
print(v)
列表
name=['alex','eric','rain']
v='_'.join(name)
print(v)
23
range(100,0,-1) python3 中循环中才一个个创建 python2 立即创建
24
答案
value=input('6+5')
v1,v2=value.split('+')
v=int(v1)+int(v2)
print(v)
自己写的
s=0
sum=0
v=input("shuru")
for a in v :
if a.isdigit() :
s=s*10+int(a)
print(s)
sum=sum+s
s = 0
print(sum)
if a=='+' :
print('sb')
print(sum)
25
sum=0
n=0
s=0
v='abcda456ea548'
for a in v :
if a.isalpha():
sum=sum+1
n=1
if a.isdigit():
s=s+n
n=0
print(sum)
print(s)
27
n="最神秘的{xxx},最打啊的{bbb},大幅度的分{ccc}"
v1=input("最神秘的是什么")
v2=input("最打啊的是什么")
v3=input("大幅度的分的是什么")
n_1=n.format(xxx=v1,bbb=v2,ccc=v3)
print(n_1)
28 不行
# ??????
# def check_code():
# import random
# checkcode =''
# for i in range(4):
# current=random.randrange(0,4)
# if current !=i:
# temp=chr(random.randint(65,90))
# else:
# temp=random.randint(0,9)
# checkcode+=str(temp)
# return checkcode
# while True:
# code=check_code()
# print(code)
# a=0
# v=input("shuru yanzhengma")
# code_lower=code.lower()
# v_lower=v.lower()
# if cmp(v_lower,code_lower) : #怎么对比这两个字符串是否相等啊
# print("right")
# break
# else:
# print("wrong")
29
test=input("shuru")
v=test.replace("情清清",'***')
v2=v.replace("蛤蟆",'***')
print(v2)
30不行
用expandtabs
len [0:20]
while True:
v1 = input('>1>')
if v1=='q':
break
v2 = input('>2>')
v3 = input('>3>')
template = "{0}\t{1}\t{2}\n"
v = template.format(v1, v2, v3)
s = s + v
print(s.expandtabs(20))
while True : # 这里不行啊,为什么
v1=input("yonghuming")
v2=input("mima")
v3=input("youxiang")
if v1 == 'q':
break
n1=v1.center(20)
n2=v2.center(20)
n3=v3.center(20)
n4=n1+n2
n5=n4+n3
print(n5)
技巧,可以在code==》》reformat code 使得代码格式更好看