Answers for "foreach array python"

5

python for loop with array

foo = ['foo', 'bar']
for i in foo:
  print(i) #outputs 'foo' then 'bar'
for i in range(len(foo)):
  print(foo[i]) #outputs 'foo' then 'bar'
i = 0
while i < len(foo):
  print(foo[i]) #outputs 'foo' then 'bar'
Posted by: Guest on July-18-2020
1

py foreach

// PHP:
foreach ($array as $val) {
    print($val);
}

// C#
foreach (String val in array) {
    console.writeline(val);
}

// Python
for val in array:
    print(val)
Posted by: Guest on June-26-2020
1

foreach loop in python

# Python doesn't have a foreach statement per se. 
# It has for loops built into the language. 
# As a side note the for element in iterable syntax comes from 
# the ABC programming language, one of Python's influences
Posted by: Guest on November-18-2020

Python Answers by Framework

Browse Popular Code Answers by Language