Home  >  Article  >  Backend Development  >  For loops and range built-in functions in python

For loops and range built-in functions in python

不言
不言Original
2018-04-17 10:38:582300browse

The following article will share with you a detailed explanation of the for loop and range built-in functions in Python. It has a good reference value and I hope it will be helpful to everyone. Let’s come and take a look.

is as follows:

1. The for loop is used with the range built-in function

range function generates a list starting from zero,

range(4) means list: 0123

range(1,11,2) means a list with a step length of 2 starting from 1 to 11-1: 13579

That is, range(i) means starting from 0 to A list of i-1, range(m,n) represents a list starting from m to n-1, range(m,n,t) represents a list starting from m with steps t to n-1

'''

print('第一次循环输出:')
for i in range(4):
 print(i)
print('第二次循环输出:')
for i in range(1,11,2):
 print(i)

# 2. The following is the number ## in the enumerated output [].

#

print('第三次循环输出:')
for i in[0,7,3]:
 print(i)


# 3. The following is the output of the defined content in sequence

print('第四次循环输出:')
foo ='a,b,m'
for i in foo:
 print(i)

Related recommendations:


How to view numpy array attributes in python3 library

Related uses of the array array module in Python

The above is the detailed content of For loops and range built-in functions in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn