12/28/2020 Untitled12
In [ ]: X="UDAIPUR"
print(X)
print("First character -", X[0])
print("Last Character -",X[6])
print("No. of characters -",len(X))
print("Last characters -",X[len(X)-1])
print("Traversing string using for loop")
for ch in X: #ch is the variable in which characheters will be accessed one b
y one
print(ch)
print("Traversing string using while loop")
i=0
while i<len(X):
print(X[i])
i+=1
print("String operators - ")
x="Udaipur"
y="Rajasthan"
print("+ Operator (x+y)- ",x+y)
print("* Operator (x*2)- ",x*2)
print("%s is the Lake city of %s"%(x,y))
print("Example of membership operator in/not in")
z="Ajmer Udaipur Bhilwara"
print("in operator - ",x in z )
print("not in operator - ",x not in z )
#How to use membership operators with if statement
a=input("First string - ")
b=input("Second string -")
if b in a:
print("Yes second string exist in first one")
else:
print("No second string does not exist in first one")
localhost:8888/nbconvert/html/Untitled12.ipynb?download=false 1/1