SoFunction
Updated on 2024-11-13

Example method for python to determine what a string ends with

function:endswith()

Role: determine whether the string ends with the specified character or sub-string, often used to determine the file type.

Related functions: determine the beginning of a string startswith()

Function Description:

Grammar:

(str, beg=[0,end=len(string)])
string[beg:end].endswith(str)

Parameter Description:

  • string: the string to be detected
  • str: specified character or sub-string (can use tuple, will match one by one)
  • beg: set the starting position for string detection (optional, counting from left)
  • end: set the end position of string detection (optional, counting from left)

If the arguments beg and end are present, they are checked in the specified range, otherwise they are checked in the whole string.

Return Value:

Returns True if a string is detected, False otherwise.

Ans: Returns True if the string string ends in str, otherwise returns False.

Example:

Create a new one in the python editor summary.

Write your own notes.

Then create a new variable testname.

Use endswith() to determine if a string ends in "ar".

Print out the results.

Select "run" - > "run".

Run the program, and if so, it returns true.

The above is python to determine what the string ends with the details of the example method, more information about python how to determine what the string ends with please pay attention to my other related articles!