1.%有哪几种含义?
查找手册
翻看《The Python Libary Reference》python库指南中附录index部分(P1899):
% (percent):
datetime format, 198, 594, 596
environment variables expansion (Windows), 377, 1798
interpolation in configuration files, 493
operator, 31
printf-style formatting, 51, 65
根据index中用法索引逐项来看:
- datetime format:表示日期格式
- environment variables expansion 环境变量扩展
- interpolation in configureation files 插入设置文件
- operator:取余
- printf-style formatting:输出格式化
环境变量扩展:
Expands environment variable placeholders %NAME% in strings like REG_EXPAND_SZ:
ExpandEnvironmentStrings('%windir%')
'C:\\Windows'
- 1
- 2
- 3
插入设置文件
home_dir: /Users
my_dir: %(home_dir)s/lumberjack
my_pictures: %(my_dir)s/Pictures
- 1
- 2
- 3
实例:
cls_info = ['%s\n(%d %s)'% (estimator_conf['name'],
estimator_conf['complexity_computer'](estimator_conf['instance']),
estimator_conf['complexity_label'])
for estimator_conf in configuration['estimators']]
- 1
- 2
- 3
- 4
2.~含义是什么?
查手册:
- ~ (tilde)
home directory expansion, 377
operator, 32
除了表示家目录外,表示操作符按位取反(the bits of inverted)
~5=-6
~-11=10
可以理解为取0为第一个正数,取坐标轴对称点。
解析见:https://blog.csdn.net/oAlevel/article/details/79267644