describe : Determines whether a string ends with a specified character or substring
Python endswith()
Method to determine whether a string ends with the specified suffix , If it ends with the specified suffix True, Otherwise return False. Optional parameters "start" And "end" To retrieve the start and end positions of a string . Returns if the string contains the specified suffix True, Otherwise return False.
grammar :str.endswith(suffix[, start[, end]])
( Explain that if there is any violation from Baidu, please contact us and delete it in time )
subject : The rules of the game are that each employee 1 Start counting in sequence , When the mantissa is 7 Number of or 7 Multiple of , The employee will not report the amount , But a pat on the leg . Employees who make mistakes will be given a small punishment —— do 10 Push ups .
# Method 1 count = 99 for n in range(1, 100): if n % 7 == 0 or str(n).endswith('7'):
# describe : Determines whether a string ends with a specified character or substring . continue count = count - 1 print(
' All employees participating in this game from 1 Count to 99 Totally {} second '.format(count)) # Method II count = 0 for n in range(1, 100):
if n % 7 == 0 or str(n).endswith('7'): count = count + 1 print(
' All employees participating in this game from 1 Count to 99 Totally {} second '.format(count))
result :
Technology