String in python.
# str="hello i am ved.\nhow you know me ?"
# print(str)
# # concatenation
# s1="ved"
# s2="varshney"
# print(s1+s2)
# # length of string
# str="shradha";
# print(len(str))
# # access character from particular index
# str="noida"
# ch=str[3]
# print(ch)
# # slicing string_name[i:j] j is not included
# # if i , j not written , then default value assigned
# str="ved varshney"
# print(str[1:7])
# print(str[1:])
# print(str[:3])
# # in pyhton , there is also negative indexing
# # like string= d e l h i
# # -5-4-3-2-1
# str ="delhi"
# print(str[-4:-1])
# strings function
#str="i am ved varshney"
# print(str.endswith("ed"))
# # capitalize() - capitalize 1st character , no change in og string
# print(str.capitalize())
# # replace()- replace all old character with new character
# print(str.replace("a","x"))
# print(str.replace("ved","sam"))
# # find()- return 1st index of 1st occurance
# print(str.find("a"))
# # count()- is used to count particular character
# str="$ symbol is used for $ currency"
# print(str.count("$"))
Comments
Post a Comment