python foreach in array code example
Example 1: python loop through list
list = [1, 3, 6, 9, 12]
for i in list:
print(i)
Example 2: 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)
Example 3: py foreach
names = ['tom', 'john', 'simon']
namesCapitalized = [capitalize(n) for n in names]
Example 4: for loop in python array
for x in range (1, 100, 1):
print(x)