1. 进制格式化输出
代码:
1 | print("bin:{:6b},{:6b},{:6b},{:6b}".format(2, 4, 8, 16)) |
输出:
1 | bin: 10, 100, 1000, 10000 |
2. 序列倒序
代码:
1 | ch = "I LOVE YOU" |
输出:
1 | UOY EVOL I |
3. * 与 ** 参数
代码:
1 | def testTuple(*a): |
输出:
1 | (1, 2, 3, 4) |
4. this库
代码:
1 | import this |
输出:
1 | The Zen of Python, by Tim Peters |
5. keyword库
代码:
1 | import keyword |
输出:
1 | ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] |
6. dis库
代码:
1 | import dis |
输出:
1 | 55 0 LOAD_FAST 0 (a) |
7. os库
代码:
1 | import os |
输出:
1 | F:\Python |
8. Unicode码
代码:
1 | ch = "0123456789\x00abcd\x00编程喵\x00(●'◡'●)" |
输出:
1 | [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 0, 97, 98, 99, 100, 0, 32534, 31243, 21941, 0, 40, 9679, 39, 9697, 39, 9679, 41] |
9. 皮卡丘~
代码:
1 | print(""" |
输出:
1 | へ /| |
10. 列表生成式
代码:
1 | print([x * x for x in range(10) if x % 2]) |
输出:
1 | [1, 9, 25, 49, 81] |
11. switch
代码:
1 | case = input("Please input a case: ") |
输出:
1 | PS F:\Python> .\test.py |
12. 提取每一位数字
代码:
1 | print(list(map(eval, list(str(2333))))) |
输出:
1 | [2, 3, 3, 3] |