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


Iterate characters with length function

Exmple: -

I = “Hello Friends

T=len(i)

Print (t)

For a in range (t):

          Print (i[a])


Iterate reverse characters with length function

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])


 



Iterate characters without length function

Exmple: -

i = “Hello Friends

For a in i:

          Print (a)

Iterate reverse characters without length function


Exmple: -

i = “Hello Friends

i=i [-1::-1]

For a in i:

          Print (a)

 

 <<Previous                                                  Next>>


कोई टिप्पणी नहीं

टिप्पणी: केवल इस ब्लॉग का सदस्य टिप्पणी भेज सकता है.

How To Convert Data in Columns into Rows in Excel Document

How To Convert Data in Columns into Rows in Excel Document Download Notepad file - Clickhere Copy code here: Function SplitCellToRows(CellVa...

Blogger द्वारा संचालित.