Professional Documents
Culture Documents
OUTPUT:
Hello
Indexing In A String.
mystr = "python"
print("String is ",mystr)
#First Character
print("First Character = ",mystr[0])
#Last Character
print("Last Character = ",mystr[-1])
#Reverse
print("Reversed String =",mystr[::-1])
OUTPUT:
String is python
First Character = p
Last Character = n
Reversed String = nohtyp
To Delete A String
mystring ="Hello World"
del mystring
print(mystring)
OUTPUT:
NameError: name 'mystring' is not defined
#Using +
print('str1 + str2=',str1 + str2)
#Using *
print('str1 * 3=',str1 * 3)
OUTPUT:
str1 + str2= HelloWorld!
str1 * 3= HelloHelloHello
OUTPUT:
3 Letters Found
String Membership Test.
>>> 'a' in 'program'
True
>>> 'at' not in 'battle'
False
Built-in Function
#Python Program To Demostrate The Use Of len() Method.
OUTPUT:
5
15
Finding.
>>> word ="Hello World"
>>> print(word.count('l'))
#Count How Many Times l Is In The String
OUTPUT:
3
>>>print(word.find("H"))
#Find The Word H In The String.
OUTPUT:
0
>>> print(word.index("World"))
#Find The Letters World In The String.
OUTPUT:
6
COUNT.
s="Count,The Number Of Spaces"
print(s.count(" "))
OUTPUT:
3
Split Strings.
word="Hello World"
print(word.split(' '))
OUTPUT:
['Hello', 'World']
Startswith/EndsWith.
Replacing
word ="Hello World"
print(word.replace("Hello","Goodbye"))
OUTPUT:
Goodbye World