“Fungsi loop Python” Kode Jawaban

Python untuk Loop

for i in range(1.10):
	print(i)
    
#output: 1,2,3,4,5,6,7,8,9,10
AMXX

Python untuk Loop

A for loop iterates through an iterable, may that be an array, a string, or a range of numbers
#Example:
myArr = ["string 1", "string 2"]
for x in myArr:
  print(x)
#Returns "string 1", "string 2". In here the x is an iterator and does not need to be defined.
Fierce Frog

Python untuk Loop

#for loop without passing a argument

for _ in range(3):
  print("Hello")
Combative Crocodile

Python untuk Loop

# Range:
for x in range(5):
  print(x) # prints 0,1,2,3,4

# Lists:
letters = ['a', 'b', 'c']
for letter in letters:
  print(letter) # prints a, b, c
  
# Dictionaries:
letters = {'a': 1, 'b': 2, 'c': 3}
for letter, num in letters.items():
  print(letter, num) # prints a 1, b 2, c 3
Benja

Python untuk Loop

for number in range(10):
  print(number)
Frightened Ferret

Fungsi loop Python

x = None # you can change this
y = None # you can change this

while x < y:
	#do something
	break
    

Glorious Gaur

Jawaban yang mirip dengan “Fungsi loop Python”

Pertanyaan yang mirip dengan “Fungsi loop Python”

Lebih banyak jawaban terkait untuk “Fungsi loop Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya