String Functions in Python-Find, Index, Isalpha, Isdigit & Isalnum Functions in Python|Tutorial

preview_player
Показать описание
find(): This is a built-in function in Python that returns the lowest index of the substring (if found). If not found, it returns -1. It is used with strings.

str = "Pycent, World!"

index(): This is another built-in function in Python that also returns the index of a substring. The difference between find() and index() is that index() raises an exception if the substring is not found.

str = "Pycent, World!"
try:
except ValueError:
print("Substring not found.")

isalpha(): This method returns True if all the characters in the string are alphabets (either lower case or upper case), otherwise, it returns False.

str = "Pycentworld"

isdigit(): This method returns True if all the characters in the string are digits, otherwise, it returns False.

str = "123456"

str = "123abc"

isalnum(): This method returns True if all the characters in the string are alphanumeric (either alphabets or digits), otherwise, it returns False.

str = "abc123"

str = "abc 123"

Рекомендации по теме