Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 19ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
c

counter

Recently created Least recently created Recently updated Least recently updated

timmy / 使用 funcy.count 進行無限計數迴圈

Last active 6 hours ago automation counter funcy generator iteration loop python

此程式使用 funcy.count 生成從 0 開始的無限計數迴圈,適用於數據生成、計時器或自動編號場景,可透過條件中斷循環。

0 0 0 1
1 from funcy import count # 匯入 funcy 模組中的 count 函式
2
3 # 使用 count 函式生成無限迴圈,從 0 開始計數
4 for i in count():
5 print(i, end="\r") # 將目前的計數 i 印出,並利用Enter符 \r 讓每次印出的數字覆蓋前一個數字的位置
6 if i >= 100_000_000: # 當計數超過或等於 100,000,000 時
7 break # 跳出迴圈