0% found this document useful (0 votes)
6 views1 page

11.1 String Example

The document contains Python code demonstrating string manipulation techniques, including accessing characters, determining string length, and traversing strings using loops. It also illustrates the use of string operators for concatenation and repetition, as well as membership operators to check for substring presence. Additionally, it includes user input to check if one string exists within another.

Uploaded by

sd342008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

11.1 String Example

The document contains Python code demonstrating string manipulation techniques, including accessing characters, determining string length, and traversing strings using loops. It also illustrates the use of string operators for concatenation and repetition, as well as membership operators to check for substring presence. Additionally, it includes user input to check if one string exists within another.

Uploaded by

sd342008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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

You might also like