String Iteration in Python
String
Iterations:
iteration
means journey. That is, we will travel on a word or sentence and extract each
character. iteration takes one character from a string. It is used with a loop.
iteration का
मतलब होता है सफर यानि हम किसी शब्द या सेंटेंस पर
सफर करेंगे और एक-एक करैक्टर को निकालेंगे.
iteration किसी string में से एक-एक करैक्टर को लेकर आता है इसका इस्तेमाल लूप के साथ होता है.
Lets
understand this with two different examples
First of all calculate the length of given string
Exmple: -
I
= “Hello Friends”
T=len(i)
Print (t)
Output:
13
Exmple: -
I
= “Hello Friends”
T=len(i)
Print (t)
For
a in range (t):
Print (i[a])
Exmple: -
i
= “Hello Friends”
i=i
[-1::-1]
T=len(i)
Print (t)
For
a in range (t):
Print (i[a])
Exmple: -
i
= “Hello Friends”
T=len(i)
Print (t)
For
a in range (t-1,-1,-1):
Print (i[a])
|
Exmple: -
i
= “Hello Friends”
For
a in i:
Print (a)
Iterate reverse characters without length function
i
= “Hello Friends”
i=i
[-1::-1]
For
a in i:
Print (a)
Post a Comment