Recipe 1.6. Combining Strings(Python Cookbook)
2010-12-19 11:43
357 查看
string 1 >>> import operator
2 >>> pieces = ['a', 'b', 'c']
3 >>> largestring = reduce(operator.add, pieces)
4 >>> largestring
5 'abc'
6 >>> faststring = ''.join(pieces)
7 >>> faststring
8 'abc'
9 >>> formatstring = '%s is %s' % ('ray', 'coding')
>>> formatstring
'ray is coding'
2 >>> pieces = ['a', 'b', 'c']
3 >>> largestring = reduce(operator.add, pieces)
4 >>> largestring
5 'abc'
6 >>> faststring = ''.join(pieces)
7 >>> faststring
8 'abc'
9 >>> formatstring = '%s is %s' % ('ray', 'coding')
>>> formatstring
'ray is coding'
相关文章推荐
- Recipe 1.4. Aligning Strings(Python Cookbook)
- Recipe 1.9. Simplifying Usage of Strings' translate Method(Python Cookbook)
- Python Cookbook 第二版 汉化版 [Recipe 16.4] 将参数与函数关联起来(Currying)
- Python Cookbook 第二版 汉化版 [Recipe 1.2] 字符与其对应的数字编码之间的转换
- Python Cookbook 第二版 汉化版 [Recipe 1.6] 字符串的组合
- Python Cookbook 第二版 汉化版 [Recipe 1.1] 逐个处理字符串中的各个字符
- Python Cookbook 第二版 汉化版 [Recipe 1.8] 检测字符串是否包含特定的字符集合
- Python Cookbook 第二版 汉化版 [Recipe 1.4] 对齐字符串
- Recipe 1.10. Filtering a String for a Set of Characters(Python Cookbook)
- Recipe 1.11. Checking Whether a String Is Text or Binary(Python Cookbook)
- Recipe 1.8. Checking Whether a String Contains a Set of Characters(Python Cookbook)
- Recipe 1.1. Processing a String One Character at a Time(Python Cookbook)
- Recipe 1.12. Controlling Case(Python Cookbook)
- Python Cookbook 第二版 汉化版 [Recipe 1.6] 字符串的组合
- Python Cookbook 第二版 汉化版 [Recipe 1.7] 以单词或字符为单位对字符串进行反序排列
- Recipe 1.5. Trimming Space from the Ends of a String(Python Cookbook)
- Python Cookbook 第二版 汉化版 [Recipe 1.3] 测试一个对象是否为 String-like 对象
- Python Cookbook 第二版 汉化版 [Recipe 1.7] 以单词或字符为单位对字符串进行反序排列
- Python Cookbook 第二版 汉化版 [Recipe 1.4] 对齐字符串
- Python Cookbook 第二版 汉化版 [Recipe 16.4] 将参数与函数关联起来(Currying)