判斷字串結尾方式

2022-08-17 19:30:26 字數 596 閱讀 8611

輸入2個字串,判斷其中乙個字串是否是以另乙個字串結尾

輸入2行,每行乙個字串資料

如果第1個字串以第2個字串結尾,輸出第2個字串 如果第2個字串以第1個字串結尾,輸出第1個字串 如果兩個字串互為對方的結尾字元,輸出'all' 如果都不滿足,輸出'no'

abc123

123

123
a=input()

b=input()

x=len(a)

y=len(b)

c=-len(a)

d=-len(b)

if x>y:

if a[d:]==b:

print(b)

else:

print("no")

elif xif a==b[c:]:

print(a)

else:

print("no")

elif x==y:

if a[c:]==b[c:]:

print("all")

else:

print("no")

判斷字串的結尾型別

通常中英文混排常常需要去判斷乙個字串是以什麼型別結尾的,用以以後的處理需要。如下 h 函式名 checkstringendtype 功 能 判斷字串的結尾型別 參 數 str in 傳入的字串 返回值 0 以ascii碼結尾 1 以漢字的高位元組結尾 2 以漢字的低位元組結尾 int checkst...

判斷字串的開始和結尾

判斷串的開始和結尾 在string類中的兩個方法 startwith 和endswith 分別來判斷開始和結束的字元,這兩個方法的返回值都是boolean型別 1.startwith 用來判斷當前字串的字首是否為引數指定的字串 2.endswith 用來判斷當前字串是否為以給定的字串結束 下面舉個例...

python判斷字串開頭或結尾

python裡判斷字串開頭或結尾,使用的是startswith和endswith兩個方法,比如str.startswith he 當str開頭是he開頭就返回true,否則就返回false。endswith是判斷以某個字串結尾,依次類推。filename trace.h print filename...