For loop with String




For loop with String

Example

Looping Through a String

Even strings are iterrable objects, they contain a sequence of characters:

Example

Loop through the letters in the word "banana":

for x in "banana":
  
print(x)

Print each fruit in a fruit list:

fruits = ["apple""banana""cherry"]
for x in fruits:
  
print(x)

The for loop does not require an indexing variable to set beforehand.


<<Previous                                                  Next>>

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

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

"Master REGEX in Excel | Boost Your Productivity with These Powerful Tips!"

 "Master REGEX in Excel | Boost Your Productivity with These Powerful Tips!" Regex (Regular expressions), is a tool that finds pat...

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