How do I use a C-style for loop in Python?

后端 未结 7 1628
南旧
南旧 2020-12-01 06:17

I want to use the traditional C-style for loop in Python. I want to loop through characters of a string, but also know what it is, and be able to jump through characters (e.

7条回答
  •  北海茫月
    2020-12-01 06:58

    for i in range(n):
    

    ...is the Python equivalent of the C...

    for (i = 0; i < n; i++){
    

    Or well, you can use:

    for i in range(a, n, s):
    

    ...which is equivalent to...

    for (i = a; i < n; i+=s){
    

提交回复
热议问题