使用 %类型 来填充 常用的有:%s 填充字符串类型:%d 填充 int 类型:这里是沿用了 C语言中 printf() 函数中的格式,更多的信息请查看:完整列表 name = 'tommy' message = 'hello %s' % name print(message) 结果是:hello tommy 同时填充多个时,需要使用元组 name = 'tommy' age = 29 message = 'my name is %s, i am %d years old.' % (name,
python 判断字符串中是否只有中文字符 学习了:https://segmentfault.com/q/1010000007898150 def is_all_zh(s): for c in s: if not ('\u4e00' <= c <= '\u9fa5'): return False return True
今天遇到的字符串处理的问题,记录一下方便使用 str1 = input('请输入一个字符:') #初始化字符.数字.空格.特殊字符的计数 lowercase = 0 uppercase = 0 number = 0 space = 0 other = 0 for strs in str1: #如果在字符串中有小写字母,那么小写字母的数量+1 if strs.islower(): lowercase += 1 #如果在字符串中有数字,那么数字的数量+1 elif strs.isdigit(): n
现在有一个需求,比如给定如下数据: 0-0-0 0:0:0 #### the 68th annual golden globe awards #### the king s speech earns 7 nominations #### <LOCATION>LOS ANGELES</LOCATION> <ORGANIZATION>Dec Xinhua Kings Speech</ORGANIZATION> historical drama British k