Today I have learned Iteration in python

 Iteration in python:

  • Technically, in Python, an iterator is an object which implements the iterator protocol, which consist of the methods __iter__ () and __next__ (). Lists, tuples, dictionaries, and sets are all iterable objects. They are iterable containers which you can get an iterator from. All these objects have a iter () method which is used to get an iterator:
    • When it comes to iteration in Python, you’ll often hear people talking about iterable objects or just iterables. As the name suggests, an iterable is an object that you can iterate over. To perform this iteration, you’ll typically use a for loop. Pure iterable objects typically hold the data themselves.
    • a= ("apple","banana","orange")
      b= iter(a)

      print(next(b))
      print(next(b))
      print(next(b))
    • Output:

      apple
      banana
      orange
    • import datetime
      
      x=datetime.datetime(2024,3,10)
      
      print(x.strftime("%A"))
    • Output:

      Sunday

Comments

Popular posts from this blog

Building a Full-Stack Student Management System with React.js and NestJS

Today I have solved the problem in javascript

Today I have solved problem in javascript