String slicing and other importants functions
SO today i am going to explain about string slicing and other important functions of the string with the help of a basic program.
# String slicing and other function of python
mystr = "i love coding" # creating a string
print(mystr) # printing the particular string
print(mystr[5]) # accessing 5th position of index of string ( we count the index from zero )
print(mystr[0:6]) # slicing the string ( starting from zero which is including but 6 is excluding)
"""Now i am going to write the code for the fuctions to perform some specific actions on the string.
you can simply understand this code by running on your device compiler"""
print(len(mystr)) # this len() function is used to find the length of the string.
print(type(mystr)) # this type() function is used to find the data type .
print(mystr.isalnum()) # this isalnum() function is used to detect that if the string is alpha numeric or not .
print(mystr.endswith("coding")) # this endswith() function is used to detect ending of the string.
print(mystr.count("o")) # this count() function is used to find number of character in the string.
print(mystr.capitalize()) # this capitalize() function is used to capitalize the first character of the string.
print(mystr.find("coding")) # this find() function is used to find the words and character in the string.
print(mystr.lower()) # this lower() function is used to smalize the strings characters.
print(mystr.upper()) # this upper() finction is used to convert the character into uppercase of the string.
print(mystr.replace("i","we")) # we use this function for replacing
"""that's all for today i am providing output image below you can see if you want to check your answer.
if you have any doubts then definitely ask in the comment section"""
OUTPUT--
YOU CAN REFER THIS SITE FOR MORE FUNCTIONS OF STRINGS--
click here
Comments
Post a Comment