python-%、~含义解释

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'

插入设置文件

home_dir: /Users
my_dir: %(home_dir)s/lumberjack
my_pictures: %(my_dir)s/Pictures

实例:

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']]

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值