Beruflich Dokumente
Kultur Dokumente
A String is group of character ,A string can hold any type of known characters i.e.
letters,numbers,symbols.
city=”Kathmandu”
K A T H M A N D U
0 1 2 3 4 5 6 7 8
- - - - -5 - - - -
9 8 7 6 4 3 2 1
Forward indexing 0,1,2,3,…..
Details
1. Traversing in string:
Name=”KV Kathmandu”
For ch in name
Print (ch,’-‘,end=,” ”)
K-V- -K-a-t-h-m-a-n-d-u
N=len(Name)
For i in range(-1,(-N-1),-1)
Print (ch,’-‘,end=,” ”)
u-d-n-a-m-h-t-………………..
3. String Operators
a. Concat +
b. Replication *
c. Membership in/not in
d. Comparision == / !=
4. String Slicing
City=”Kathmandu”
len(city)- 9
5. Built-in :String Manipulation Methods:
a. String.capitalize()
msg=”kv is our school”
print msg.capitalize():Kv is our school
b. String.find(sub,start,end):to find position of a substring in a given string
Str=”Kathmandu”
Str.find(“th”,1,8) 2
Str.find(“th”,7,8) -1
Str.find(“td”,1,8) -1
d. String.isalpha()
S1=”*adfddfgfd”
if (S1.isalpha()) -False
e. String.isdigit()
S1=”5”
if (S1.isdigit()) -True
S1=”A”
if (S1.isdigit()) -False
f. String.islower()
S1=”a”
if (S1.islower()) -True
g. String.isupper()
h. String.isspace()
s2=” ”
if (s2.isspace()) -True
i. String.upper()
S1=”kAThManDU”
S2=S1.upper()
print (s2) KATHMANDU
String.lower()