Python range function All In One
Python range function All In One
range 函数
函数语法
range(stop)
range(start, stop[, step])
参数说明:
start: 计数从 start 开始。默认
是从 0
开始。例如 range(5) 等价于
range(0, 5)
stop: 计数到 stop 结束,但不包括
stop。例如:range(0, 5) 是 [0, 1, 2, 3, 4] 没有 5
step:步长,默认
为 1
。例如:range(0, 5) 等价于
range(0, 5, 1)
RGB
color 0 ~ 255
二进制 2 ** 8
=> 256
# 简写
for i in range(255):
print("i =", i)
# 等价于
for i in range(0, 255):
print("i =", i)
# 等价于,全写
for i in range(0, 255, 1):
print("i =", i)
demos
#!/usr/bin/python3
from time import sleep
n = 30
m = 2
# while True:
while m > 0:
m = m - 1
for i in range(0, n, 1):
if(i % 3 == 0):
print("\n❌ R =", i)
elif(i % 3 == 1):
print("✅ G =", i)
else:
print("🅿️ B =", i)
print("🐍 m =", m)
# sleep(1)
"""
$ py3 ./range.py
$ py3 ./range.py | grep "🐍"
https://www.runoob.com/try/runcode.php?filename=HelloWorld&type=python3
https://www.runoob.com/python3/python3-func-range.html
"""
➜ Python git:(master) ✗ py3 ./range.py | grep "🐍"
🐍 m = 1
🐍 m = 0
➜ Python git:(master) ✗ py3 ./range.py | grep "✅"
✅ G = 1
✅ G = 4
✅ G = 7
✅ G = 10
✅ G = 13
✅ G = 16
✅ G = 19
✅ G = 22
✅ G = 25
✅ G = 28
✅ G = 1
✅ G = 4
✅ G = 7
✅ G = 10
✅ G = 13
✅ G = 16
✅ G = 19
✅ G = 22
✅ G = 25
✅ G = 28
➜ Python git:(master) ✗
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
https://www.runoob.com/try/runcode.php?filename=HelloWorld&type=python3
https://www.runoob.com/python3/python3-func-range.html
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17391959.html
未经授权禁止转载,违者必究!