String Python

 # # str="""hello"""

# print(str)

# 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 , can not change  
# str="noida"
# ch=str[3]
# print(ch)

# # slicing string_name[i:j:step] j is not included
# # if i , j not written , then default value assigned , step default value is 1
# upper bound does not matter

# str="ved varshney"
# print(str[1:7])
# print(str[1:])
# print(str[:3])

# str="pwskills"
# print(str[0:8:2])
# print(str[::2])

# reverse print
# print(str[::-1])

# # 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 of word or character
# if not present then -1
# print(str.find("a"))

# # count()- is used to count particular character/word
# str="$ symbol is used for $ currency"
# print(str.count("$"))

# upper case -
# str="ved varshney"
# print(str.upper())

# lower case-
# ptr="VED"
# print(ptr.lower())

# title() - convert every words 1st letter into capital
# str="ved varshney is human"
# print(str.title())

#  in string we can add/concate  only string.

#  * -> repeat n times
# str="ved"
# print(str*3)

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.