To continue to learn ~

Encoded development:

  Initial, First there is ASCII code, wherein each element representing 8 bits, i.e. one byte. as the picture shows:

  

  A byte, 8 bits, 8 * 2 = 256, i.e., a byte may identify up to 256 characters. This is the Western countries is completely sufficient.

  Later, with the computer popularization and development worldwide, but also increasingly multilingual needs identified on the computer, the characters represented by a byte far enough.

  So Chinese-based encoding, in 1980, China's State Administration issued a standard GB2312, which contains more than 7,000 characters.

  In 1995, GB18030 can now store more than 20,000 Chinese characters commonly used Chinese encoding GBK, and Chinese mode Windows default encoding is GBK, not utf-8

  International standard is the Unicode encoding, wherein a Chinese or English letters are accounted for two bytes.

  utf-8 is a Unicode-based set of extensions, of a variable length character encoding set, the English one byte characters, a character 3 bytes.

   Which details the allocation relationship can be seen here: https://cloud.tencent.com/developer/article/1343240

python, the binary string conversion and

python 3.x does not support binary string and stitching, thus before the operation between the two need to be converted.

1 msg = "我爱北京天安门"
2 print(msg.encode("utf-8"))   // 字符串转换成二进制
3 
4 msg_en = b'\xe6\x88\x91\xe7\x88\xb1\xe5\x8c\x97\xe4\xba\xac\xe5\xa4\xa9\xe5\xae\x89\xe9\x97\xa8'
5 print(msg_en.decode("utf-8")) // 二进制 转换成 字符串
二进制与字符串的转换

三种格式匹配输出

 1 # @Author  : Hozi
 2 # @Time    : 2020/3/3 16:34
 3 
 4 # 读取输入  , 此处默认都是str类型。
 5 name = input("name:")
 6 age = input("age:")
 7 job = input("job:")
 8 salary = input("salary:")
 9 
10 # 格式输出的三种方式
11 # 直接拼接法。(最好不要用拼接)
12 info = """
13 --------- info of """+name +"""---------
14 name :""" + name + """
15 age  :""" + age + """
16 job  :""" + job + """
17 salary:""" + salary
18 
19 print(info)
20 
21 # 占位符方法
22 info2 = """
23 --------- info of %s---------
24 name :%s
25 age  :%s
26 job  :%s
27 salary:%s
28 """ % (name, name, age, job, salary)
29 
30 print(info2)   
31 
32 # .format()方法
33 info3 = """
34 --------- info of {_name}---------
35 name :{_name}
36 age  :{_age}
37 job  :{_job}
38 salary:{_salary}
39 """.format(
40     _name=name,
41     _age=age,
42     _job=job,
43     _salary=salary)
44 
45 print(info3)
View Code

第三方库 os 和 sys

 1 # @Author  : Hozi
 2 # @Time    : 2020/3/3 19:15
 3 
 4 import sys
 5 print(sys.path)     # 打印环境变量
 6 
 7 print(sys.argv)     # 是一个从程序外部获取参数的命令,其是一个列表。
 8 """
 9 test.py 文件中内容 : a = sys.argv; print(a) 
10 在命令端执行:
11 输入 test.py    --> 文件路径
12 输入 test.py 0,1,2  --> ['文件路径','0','1','2'] 。 若代码改为 a = sys.argv[1],此处输出为 0
13 
14 """
15 import os
16 # print(os.system("dir"))  # 查看当前文件所在目录,只执行,不保存结果
17 
18 # cmd_res = os.popen("dir").read() # 查看当前文件所在目录,执行且保存结果到cmd_res中
19 # print(cmd_res)
20 
21 os.mkdir("new_dir")     # 在当前目录新建文件夹。
View Code

 

  

Guess you like

Origin www.cnblogs.com/Houlex/p/12404838.html