Skip to content

Commit c4d2a53

Browse files
add day-01 day-02
1 parent 4e6b9b6 commit c4d2a53

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

day-01/data-typpes-and-variables.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# 整数
2+
import math
23
from math import inf
34
a = 100
45
# 浮点数
@@ -83,3 +84,8 @@
8384
print(9 // 3)
8485
print(10 % 3)
8586
print(9 % 3)
87+
# 无限大的数
88+
print(10e100)
89+
90+
print(float('NaN'))
91+
print(math.isnan(0))

day-02/string-and-encoding.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,30 @@
2424

2525
# 格式化字符串 %s:表示字符串 %d:表示整数 %x:表示16进制数整数 %f:表示浮点数
2626
print('hello, %s' % 'dreamapple')
27-
print('%d-%d-%d' % (2017, 3, 21))
27+
print('%d-%d-%d' % (2017, 3, 21))
28+
29+
# 第二次学习
30+
print(ord('鹏'))
31+
print(ord('救'))
32+
print(ord('命'))
33+
print(ord('爱'))
34+
print(chr(29233))
35+
36+
# 编码的转换
37+
print(b'ABC')
38+
print('ABC'.encode('ascii')) # 转化为相应的字节
39+
print('我爱你'.encode('utf-8'))
40+
print(b'\xe6\x88\x91\xe7\x88\xb1\xe4\xbd\xa0'.decode('utf-8'))
41+
print(b'ABC'.decode('ascii'))
42+
print(b'\xe6\x88\x91'.decode('utf-8'))
43+
44+
# 求字符串的长度或者字节数
45+
print(len('中国'))
46+
print(len('中国'.encode('utf-8')))
47+
48+
# 格式化字符串
49+
print('Hello, %s' % 'world')
50+
# 单引号和双引号要区别开来
51+
print("Hello, %s; my name is %s" % ('world', 'dreamapple'))
52+
# 输出%
53+
print('print %%, %s' % 'hello')

0 commit comments

Comments
 (0)