startswith() function in python by R4R Team

-startswith() is a python string function which check the string starting point and return True and False as per the argument.

Example-

string is s="mytext"
s.startswith("m") will give True
s.startswith("my") will give True
s.startswith("text") will give False
s.startswith("mytext") will give True

program-

s="someway"
print("Original string is ",s)
print(s.startswith("s"))
print(s.startswith("some"))
print(s.startswith("way"))
print(s.startswith("sume"))
print(s.startswith("someway"))


output-

Original string is someway
True
True
False
False
True


-In this program, string "someway" is starts with the "s" and "some" and "someway" so it will give True but in case of "way" and "sume" it will give False.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!