python创建写模式的缩写_Python - 缩写(capwords) 和 创建转换表(maketrans) 详细说明

缩写(capwords) 和 创建转换表(maketrans) 详细说明

本文地址: http://blog.csdn.net/caroline_wendy/article/details/27051977

string模块, 包括处理文本的常量和类.

capwords(), 把字符串(string)中, 全部单词的首字母大写;

maketrans(), 创建对比表, 然后使用translate()函数, 调用对比表, 把字符串(string)中的字符, 进行对应的替换.

代码:

# -*- coding: utf-8 -*-

‘‘‘

Created on 2014.5.26

@author: C.L.Wang

‘‘‘

import string

s = ‘The quick brown fox jumped over the lazy dog.‘

leet = string.maketrans(‘abcdefg‘, ‘1234567‘) #leet 脑残

if __name__ == ‘__main__‘:

print(s)

print(string.capwords(s)) #首字母大写

print(s.translate(leet)) #转换

pass

输出:

The quick brown fox jumped over the lazy dog.

The Quick Brown Fox Jumped Over The Lazy Dog.

Th5 qui3k 2rown 6ox jump54 ov5r th5 l1zy 4o7.

44141c646b3180b5c1131323d61f997d.png

版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值