Pro syntaxi smyčky v Pythonu

Příklady kódu

68
0

python smyčky

#x starts at 1 and goes up to 80 @ intervals of 2
for x in range(1, 80, 2):
  print(x)
29
0

python pro smyčku

for x in (list):
  print(x)
12
0

pro v Pythonu

for i in range(1,10,2): #(initial,final but not included,gap)
  print(i); 
  #output: 1,3,5,7,9
  
for i in range (1,4): # (initial, final but not included)
  print(i);
  #output: 1,2,3 note: 4 not included

for i in range (5):
  print (i);
  #output: 0,1,2,3,4 note: 5 not included

python = ["ml","ai","dl"];  
for i in python:
  print(i);
  #output:  ml,ai,dl
  
for i in range(1,5):	#empty loop...if pass not used then it will return error
  pass; 	
  
9
0

pytho smyčky

for x in loop:
	print(x)
4
0

jak používat pro smyčky python

#simple for loop to print numbers 1-99 inclusive
for i in range(1,100):
  print(i)
  
#simple for loop to loop through a list
fruits = ["apple","peach","banana"]
for fruit in fruits:
  print(fruit)
1
0

python pro smyčku

# Python for loop

for i in range(1, 101):
  # i is automatically equals to 0 if has no mention before
  # range(1, 101) is making the loop 100 times (range(1, 151) will make it to loop 150 times)
  print(i) # prints the number of i (equals to the loop number)
  
for x in [1, 2, 3, 4, 5]:
  # it will loop the length of the list (in that case 5 times)
  print(x) # prints the item in the index of the list that the loop is currently on

V jiných jazycích

Tato stránka je v jiných jazycích

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................