相关疑难解决方法(0)

格式化字符串时多次插入相同的值

我有一个这种形式的字符串

s='arbit'
string='%s hello world %s hello world %s' %(s,s,s)
Run Code Online (Sandbox Code Playgroud)

字符串中的所有%s都具有相同的值(即s).有没有更好的写作方式?(而不是列出s三次)

python string format

101
推荐指数
4
解决办法
11万
查看次数

如何在Python中使用不带0x的hex()?

hex()python中的函数将前导字符0x放在数字的前面.无论如何要告诉它不要把它们放?所以0xfa230fa230.

代码是

import fileinput
f = open('hexa', 'w')
for line in fileinput.input(['pattern0.txt']):
   f.write(hex(int(line)))
   f.write('\n')
Run Code Online (Sandbox Code Playgroud)

python

76
推荐指数
7
解决办法
11万
查看次数

标签 统计

python ×2

format ×1

string ×1