The startswith and endswith functions in Python use instances, startswithendswith
In Python, there are two functions: startswith () and endswith (). The functions are very similar. The startswith () function determines whether the text starts with a certain character, endswith () the function determines whether the text ends with a certain character.
Startswith () function
This function determines whether a text starts with a certain number of characters and returns True or False.
Copy codeThe Code is as follows:
Text = 'Welcome to qttc blog'
Print text. startswith ('W') # True
Print text. startswith ('wel') # True
Print text. startswith ('C') # False
Print text. startswith ('') # True
Endswith () function
This function determines whether a text ends with one or more characters and returns True or False.
Copy codeThe Code is as follows:
Text = 'Welcome to qttc blog'
Print text. endswith ('G') # True
Print text. endswith ('Go') # False
Print text. endswith ('og ') # True
Print text. endswith ('') # True
Print text. endswith ('G') # False
Determine whether the file is an exe execution File
We can use endswith(registry.txt file name is not ended with .exe to determine whether the file is executable.
Copy codeThe Code is as follows:
# Coding = utf8
Filename1}'qttc.exe'
If(fileName1.endswith('.exe ')):
Print 'this is an exe execution file'
Else:
Print 'this is not an exe execution file'
# Execution result: This is an exe execution file.
Determine whether the filename suffix is an image
Copy codeThe Code is as follows:
# Coding = utf8
Filename1}'pic.jpg'
If fileName1.endswith('.gif ') or fileName1.endswith('.jpg') or fileName1.endswith('.png '):
Print 'this is an image'
Else:
Print 'this is not an image'
# Execution result: this is an image.
StartsWith () and endsWith () Methods of java string classes
First fill in ed
The second parameter is showMessageDialog (null, output)
This is the subject of the school examination?
This is boring only when the exam is answered.
Use of pow (x, y [, z]) functions in python
Your syntax is incorrect.
X and y in the built-in power (x, y [, z]) functions are mandatory, and z is an optional parameter. If the parameter z is used, brackets must be removed, that is, power (x, z, y, z). The result is that the y power of x is used to calculate the remainder of z. However, this method is more efficient than power (x, y) % z.
You can use power (2, 4) or power (2, 4, 3 ).
Power (2, 4) = power 4 of 2 = 16;
Power (2, 4, 3) = 4 power of 2 and then modulo 3 = 16% 3 = 1.