“Für Loops Python” Code-Antworten

Python für Schleife

# 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
Unknown Species

Python für Schleife

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

Python für Schleife

for x in range(6): #The Loop
  print(x) #Output 0,1,2,3,4,5
Vasilije Dimitrijevic

Wie man in Python eine Schleife macht

x = 0
while True: #execute forever
	x = x + 1
	print(x)
Taraxtix

Für Loops Python

text = "Hello World"
for i in text:
  print(i)
#Output
#H, e, l, l, o, , W, o, r, l, d
for i in range(10):
  print(i)
#1, 2, 3, 4, 5, 6, 7, 8, 9, 10
TheProgrammer

Für Loops Python

# There are 2 types of loops in python
# while loops and for loops
# a while loops continues for an indefinite amount of time
# until a condition is met:

x = 0
y = 3
while x < y:
    print(x)
    x = x + 1

>>> 0
>>> 1
>>> 2

# The number of iterations (loops) that the while loop above
# performs is dependent on the value of y and can therefore change

######################################################################

# below is the equivalent for loop:
for i in range(0, 3):
    print(i)

>>> 0
>>> 1
>>> 2

# The for loop above is a definite loop which means that it will always
# loop three times (because of the range I have set)
# notice that the loop begins at 0 and goes up to one less than 3.
codeconnoisseur

Ähnliche Antworten wie “Für Loops Python”

Fragen ähnlich wie “Für Loops Python”

Weitere verwandte Antworten zu “Für Loops Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen