日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

range函数python_range()函数以及Python中的示例

發布時間:2025/3/11 python 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 range函数python_range()函数以及Python中的示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

range函數python

Python range()函數 (Python range() function)

The range() is a built-in function in Python which returns the sequence of values. It is used where we need to perform a specific action for a limited number of times. In general, if we write range starting from a value i and end up to the value j then we will get a sequence i, i+1 up to j-1.

range()是Python中的內置函數,它返回值的序列。 它用于需要有限次數執行特定操作的地方。 通常,如果我們寫一個從值i開始到值j的范圍,那么我們將得到一個序列i , i + 1到j-1 。

Syntax of range() function:

range()函數的語法:

range(start, end, step)

It generally takes three arguments which are the following,

通常需要以下三個參數,

  • start: It is an integer from which the sequence has to start that is starting integer of the sequence of the integer.

    start :它是必須從其開始的整數,它是整數序列的起始整數。

  • end: It is an integer before which the sequence of integers is to be generated. Generally, if we provide an integer j then it generates sequence up to j-1.

    end :它是一個整數,在此之前將生成整數序列。 通常,如果我們提供整數j,則它會生成最多j-1的序列。

  • step: It is used to determine the difference or increment between each integer in the sequence.

    step :用于確定序列中每個整數之間的差或增量。

There are three-way by which we can call the range in the program which is the following,

我們可以通過以下三種方式在程序中調用范圍:

  • range(end):

    范圍(結束) :

    We will give only one argument ending in the

    我們只會給出一個以

    range() function when we want to start the sequence of the integer with 0. If we give the value of end is j the this is seen as a sequence whose upper limit is j and the lower limit is 0 and step is 0.

    當我們想以0開頭整數序列時,會使用range()函數。如果給定end的值為j,則這將被視為一個序列,其上限為j,下限為0,step為0。

  • range(start, end):

    范圍(開始,結束) :

    When the user decides to generate the sequence starting with a specific integer and also end before a specific integer then they call the range function with the two-argument. When the user gives the value of start then it works like the range function with one argument i.e

    當用戶決定生成以特定整數開頭并以特定整數結尾的序列時,他們將使用兩個參數調用range函數。 當用戶提供start的值時,它的工作方式類似于帶有一個參數的range函數,即

    range(end) because the range() function by default starts the sequence with zero.

    range(end),因為默認情況下range()函數從零開始序列。

  • range(start, end, step):

    范圍(開始,結束,步驟) :

    When we want to generate a sequence where we skip or increment the sequence integer by a value other than 1 that is we want a kind of arithmetic progression which have a common difference greater than 1 then we call the

    當我們要生成一個序列時,我們將序列整數跳過或增加一個非1的值,即我們想要一種算術級數,其公有差異大于1,則我們稱

    range() function with the three arguments. If we call a range() function with no step then by default it goes for 1.

    具有三個參數的range()函數 。 如果我們不帶任何步長調用range()函數 ,則默認情況下它為1。

  • Let's see an example by which we understand it in a better way.

    讓我們看一個例子,通過它我們可以更好地理解它。

    Program:

    程序:

    #call range() with one argument print('First sequence:') for k in range(10):print(k,end=' ') print()#call range() with two argument print('Second sequence:') for k in range(2,10):print(k,end=' ') print()#call range() with two argument print('Third sequence:') for k in range(2,20,1):print(k,end=' ') print()#call range() with negative step print('Fourth sequence:') for k in range(20,1,-2):print(k,end=' ') print()

    Output

    輸出量

    First sequence: 0 1 2 3 4 5 6 7 8 9 Second sequence: 2 3 4 5 6 7 8 9 Third sequence: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Fourth sequence: 20 18 16 14 12 10 8 6 4 2

    翻譯自: https://www.includehelp.com/python/range-function-with-example.aspx

    range函數python

    總結

    以上是生活随笔為你收集整理的range函数python_range()函数以及Python中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。