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


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

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

Send Multiple Emails From Excel | Send Bulk Mail from Excel Sheet with Attachment in One Click

Send Multiple Emails From Excel | Send Bulk Mail from Excel Sheet with Attachment in One Click Download VBA Code Notepad file - Click here D...

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