Post

PythonPython

r
ravi sankar

Posted on 27th February 2024|39 views

0
votes

Foreach Python

Is there a foreach function in python 3?

Answers
P
imran mohammad

Posted on 27th February 2024

No, there isn't any foreach function in python3, but we can use for loop instead. 

Syntax: 

for element in iterable

operate(element)

But if you want foreach, then you can define your own foreach function

def foreach(My_function, iterable):

for element in iterable:

function(element)

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos