学习“廖雪峰的官方网站:Python教程”时做的笔记
name = input('please enter your name')
print('Hello,' name)
print(0x_1_f)
print(2.0e1)
print('I\'m \"OK\"!')
print(r'C:\temp\new')
print('''line1 x
line2 xx
line3 xxx''')
print(True or False)
a = 1
print(type(a))
a = str(a)
print(type(a))
a = 'A'
b = a
a = 'Z'
print(b)
a = [1]
b = a
a = [1, 2]
print(b)
b = a
a.append(3)
print(b)
'''
ASCII (计算机是美国发明的,最早只有127个字符) ->
GB2312 (中国自己的,多语言混合文本会乱码) ->
Unicode (多语言统一,常用2字节的UCS-16) ->
UTF-8 (可变长,节约,英文字母1字节,汉字3字节,生僻4-6字节)
'''
print('含中文的str')
i = ord('中')
print(i)
print(chr(i))
x = 'ABC'.encode('ascii')
print(x, x.decode('ascii'))
y = '中'.encode('utf-8')
print(y, y.decode('utf-8'))
print('%s, %s100%%' % ('Hello', 'world'))
print('%3d-%03d' % (3,1))
PI = 3.1415926
print('%05.2f' % PI)
print('{0}, {1:04.1f}'.format('Hello', PI))
print(f'{PI}, {PI:04.1f}')
l = [1, 'two']
l.append(3)
l.insert(0, False)
l.pop()
l.pop(0)
t = (1,)
t = (1, ['a', 'b'])
t[1][0] = 'A'
print(t)
d = {'a': 97, 'b': 98}
print(d['a'])
print('c' in d)
print(d.get('c', -1))
d.pop('b')
s = set([1, 2, 3, 2])
s.add(2)
s.remove(3)
|