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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章