python string

python字符串使用

class string.Formatter¶
The Formatter class has the following public methods:
format(format_string, *args, **kwargs)
The primary API method. It takes a format string and an arbitrary set of positional and keyword arguments. It is just a wrapper that calls vformat().(这个函数调用vformat)
Changed in version 3.7: A format string argument is now positional-only.
vformat(format_string, args, kwargs)
This function does the actual work of formatting. It is exposed as a separate function for cases where you want to pass in a predefined dictionary of arguments, rather than unpacking and repacking the dictionary as individual arguments using the *args and **kwargs syntax. vformat() does the work of breaking up the format string into character data and replacement fields. It calls the various methods described below.

	a,b,c,d=1,2,3,4
	print("{1}{2}{3}{0}".format(a,b,c,d))

输出: 2341

字符串long是否以short开头
   def compare_two_string_opening(long,short):
   	for position in range(len(short)):
   		if long[position]!=short[position]:
   			return False
   		return True
    def compare_two_string_opening_v1(long,short):
    	lenth=len(short)
    	begining=long[0:lenth]
    	if begining==short:
    		return True
    	else
    		return False
 def compare_two_string_opening_v2(long,short):
 	return long[0:len(short)]==short
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值