Advertisement
startswith(value, start, end)
Parameters | Description |
---|---|
value | This is a string value, which is searched in the invoked string. A non-optional attribute. |
start | This is an integer value to specify the index position(zero-based index) to start the search at. An optional attribute. |
end | An integer value to specify the index position(one-based index) to end the search at. An optional attribute. |
# Python - Example of startswith() method.
# Creating a string
s1 = 'Hello World'
# Printing the value of string
print('String is : ', s1)
# Checking if the string starts with the value 'He'
b1 = s1.startswith('He')
print('Does ', s1 , ' starts with He ? ', b1)
# Checking if the string starts with the value 'Hello'
b2 = s1.startswith('Hello')
print('Does ', s1 , ' starts with Hello ? ', b2)
# Checking if the string starts with the value 'World'
b3 = s1.startswith('World')
print('Does ', s1 , ' starts with World ? ', b3)
String is : Hello World
Does Hello World starts with He ? True
Does Hello World starts with Hello ? True
Does Hello World starts with World ? False
Advertisement
# Python - Example of startswith() method.
# Creating a string
s1 = 'World Peace'
# Printing the value of string
print('String is : ', s1)
# Checking if the string starts with the value 'World'
b1 = s1.startswith('World')
print('Does ', s1 , ' starts with World ? ' , b1)
# Checking if the string starts with the value 'world'
b2 = s1.startswith('world')
print('Does ', s1 , ' starts with world ? ', b2)
# Checking if the string starts with the value 'WORLD'
b3 = s1.startswith('WORLD')
print('Does ', s1 , ' starts with WORLD ? ', b3)
String is : World Peace
Does World Peace starts with World ? True
Does World Peace starts with world ? False
Does World Peace starts with WORLD ? False
# Python - Example of startswith() method.
# Creating a string
s1 = 'Always think positive!'
# Checking if the string has a value 'always', starting at index 0 and ending at 15
# which is true because the value 'always' starts at index 0
b1 = s1.startswith('Always', 0, 15)
print(b1)
# Checking if the string has a value 'think', starting at index 7 and ending at 20
# which is true because the value 'think' starts at index 7
b1 = s1.startswith('think', 7, 20)
print(b1)
# Checking if the string starts with the value 'ways', starting at index 2 and ending at 10
# which is true because the value 'ways' starts at the index 2
b2 = s1.startswith('ways', 2, 10)
print(b2)
# Checking if the string starts with the value 'positive, starting at index 5 and ending at index 10
# which is false because the value 'positive' does not start at the index 5
b3 = s1.startswith('positive', 5, 10)
print(b3)
True
True
True
False
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement