Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7907867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:40:17+00:00 2026-06-03T11:40:17+00:00

I was checking out str objects in Python, and I realized that str object

  • 0

I was checking out str objects in Python, and I realized that str object in Python 2.7 doesn’t have either __iter__() method nor next() method, while in Python 3.0 str objects have __iter__() method, and thus they are iterable. However, I can still use str objects as if they are iterable’s in Python 2.7. For example, I can use them in for loops. How does this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:40:19+00:00Added an answer on June 3, 2026 at 11:40 am

    Simple answer: because iter(s) returns an iterable object.

    Longer answer: iter() looks for an __iter__() method, but if it doesn’t find one it tries to construct and iterator itself. Any object that supports __getitem__() with integer indices starting at 0 can be used to create a simple iterator. __getitem__() is the function behind list/string indexing operations, eg s[0].

    >>> "abc".__iter__()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'str' object has no attribute '__iter__'
    >>> iter("abc")
    <iterator object at 0x1004ad790>
    >>> iter("abc").next()
    'a'
    

    See here for details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm checking out these neat Templated Helpers that have juts been released with the
I have been checking out some of the possible timers lately, and System.Threading.Timer and
I was checking out the Tweet# API, and notice that there are 2 ways
Checking out AppHarbor today. My primary question is in the title, but I have
I was just checking out 906.gs css code and noticed that they made all
I have recently had a few issues when checking out a colleagues ASP.NET project,
I just started checking out OpenOffice's Macro system. I have 3.2.0 installed but it
Just checking out Android development very superficially, and it seems that most everyone is
After checking out code for the first time from a repository into Eclipse using
After checking out a branch in a repository git always prints a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.