Python学习之路--理论,例子

ASCII: 字母,数字,特殊字符:一个字节,8位
Unicode:16位,两个字节, 升级:32位 四个字节
utf-8:最少一个字节 8位表示。 英文字母 8位 1个字节
欧洲 16位 2个字节
中文 24位 3个字节
gbk:英文 1个字节 中文 2个字节
int:bit_length()
bool:True False
str:str --->bool:''--->False
切片
s='dfhj'
s1 = s[1]
s2 = s[1:3]
s3 = s[0:] x[:]
s4 = s[0:-1]
s5 = s[0:3:2]
s6 = s[2::-2]

方法
cap...首字母大写
upper()全大写
lower()全小写
find()通过元素找索引,找不到返回-1
index()通过元素找索引,找不到报错
swpcase() 大小写翻转
replace(old,new,count=None)替换
isdigit()返回bool值
isapha()
startwith() endwith() 切片 以什么开头、结尾
title()首字母大写
center()居中
strip() lstrip() rstrip()去空格
split()
format()格式化输出
‘{},{}’.format()
’{0},{1},{0}‘.format()
'{name},{age},'.format(name='',age='')

len()长度
count(sub,start=None
for i in 可迭代对象:
pass
s = '132a4b5e'
s1 = s[0] + s[2] + s[1]
print(s1)
s = 'asdfer'
for i in s:
    print(i)
index = 0
while 1 :
    print(s[index])
    index += 1
    if index == len(s):
        break
View Code
#加法计算器
content = input('请输入加法内容 ').strip()  #r如5+9.然后进行分割再进行计算
c1 = content.split('+')
num = 0
for i in c1 :
    num += int(i)
print(num)

content = input('请输入加法内容 ').strip()
index = content.find('+')
a =int (content[0:index])
b = int(content[index+1:])
print(int(a + b))
View Code
#任意输入一大串文字 + 数字 统计出来数字的个数
s = input('请输入:')
count = 0
for i in s:
    if i.isdigit():
        count += 1
print(count)
View Code

 

posted on 2019-05-23 12:03  久加  阅读(146)  评论(0)    收藏  举报