python‘s second day for me

in     not in 

主要用来检测一些字符串是否存在,或者避免一些字符串

1 while True:
2     comment = input('请输入你的评论')
3     if '顾清秋' in comment:
4         print('你输入的信息由敏感词汇,请重新输入')
5     else:
6         print('评论成功')
7         break
View Code
1 while True:
2     infor = input('请输入你的名字')
3     if infor == '顾清秋':
4         print('您输入的信息有敏感词汇,请重新输入')
5     else:
6         print('输入成功')
7         break
View Code

while else语句

如果while循环被break打断则不会走else,其他的则会继续走else。

1 count=1
2 flag=True
3 while flag:
4     print(count)
5     if count ==3:
6         flag = False
7     count+=1
8 else:
9     print('循环正常完毕')
View Code

% 占位符 s str  字符串 d digit 数字

1

1 name = input('请输入你的名字')
2 age = input('请输入你的年龄')
3 hobby = input('请输入你的爱好')
4 msg = '我叫%s, 今年%d岁, 爱好%s' % (name,int(age),hobby)
5 print(msg)
View Code

2

dic = {'name':'顾清秋''age':17,'hobby':'Music'}
msg = '我是%(name)s, 今年%(age)d岁, 我喜欢%(hobby)s' % dic
print(msg)

在格式化输出中单纯的显示 % 用 %%解决

1 name = input('请输入你的姓名')
2 age = input('请输入你的年龄')
3 msg = '我叫%s, 今年%d岁, 学习进度位1%%' % (name,int(age))
4 print(msg)

运 算 符 

and or not

第一种:前后都是比较运算

优先级:()> not > and > or   同一个优先级,从左至右依次计算

第二种:前后都是数值运算。

  x or y if x True 则 return x , 否则 return y

1 print(1 or 3)
2 print(1 or 3)
3 print(2 or 3)
4 print(0 or 3)
5 print(-1 or 3)
6 print(1 and 2)
7 print(0 and 2)
View Code

数据类型转换

int ---> bool  非0即为True

bool ---> int True == 1   false == 0

1 print(int(True))
2 print(int(False))
3 print(bool(10))
4 print(bool(0))
View Code

字符编码的发展史

1.ASCII   包含数字,英文,特殊字符。八位

      8位 = 1 byte 表示一个字符

    缺点:应用不广泛,不能包含中文等,,,

2.万国码 Unicode 将所有国家的语言包含在这个密码本中。

    初期:16位,两个字节,表示一个字符。

    升级:32位,四个字节,表示一个字符。

    缺点:资源浪费。

3.utf-8。最少用8位(一个字节),表示一个字符。

    英文:8位,一个字节表示一个字符。

    欧洲:16位,两个字节表示一个字符。

    亚洲:24位,三个字节表示一个字符。

    

4.utf-6 ...

gbk:国标。

   GBK是采用单双字节变长编码,英文使用单字节编码,完全兼容ASCII字符编码,中文部分采用双字节编码。

   只包含:中文,英文。

 8 Bit = 1 Byte

1024 Byte = 1 KB

1024 KB = 1 MB

1024 MB = 1 GB

1024 GB = 1 TB

  

原文地址:https://www.cnblogs.com/stfei/p/8603035.html