037 range function tủ tài liệu training

3 18 0
037 range function tủ tài liệu training

Đang tải... (xem toàn văn)

Thông tin tài liệu

range() function The range() function returns an immutable sequence object of integers between the given start integer to the stop integer range(start, stop,[step]) > step size is optional range(stop) -> We can give just stop size In this time, it will start from zero as default In [1]: range(0,15) Out[1]: range(0, 15) In [2]: print(*range(0,15)) 10 11 12 13 14 In [3]: a = list(range(0,15)) print(a) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] In [4]: a Out[4]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] In [5]: print(*range(7,15)) 10 11 12 13 14 In [6]: start = stop = 15 print(*range(start,stop)) 10 11 12 13 14 If we don't specify starting value, it will start from as default In [7]: print(*range(10)) In [8]: print(*range(0,50,2)) #step size 2 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 The Complete Python Programming Course: (Beginner to Advanced) In [9]: print(*range(1,99,3)) #step size 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 91 94 97 In [10]: print(*range(0,40,5)) #step size 5 10 15 20 25 30 35 In [11]: print(*range(20,0)) #countdown In [12]: print(*range(15,0,-1)) # countdown 15 to 15 14 13 12 11 10 In [13]: for i in range(0,20): print(i) 10 11 12 13 14 15 16 17 18 19 In [14]: for i in range(1,10,): print(i*"+") + ++ +++ ++++ +++++ ++++++ +++++++ ++++++++ +++++++++ In [15]: for i in range(10,0,-1): print(i * "+") ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ + The Complete Python Programming Course: (Beginner to Advanced) In [16]: for i in range(10,0,-1): print(i*"★") ★★★★★★★★★★ ★★★★★★★★★ ★★★★★★★★ ★★★★★★★ ★★★★★★ ★★★★★ ★★★★ ★★★ ★★ ★ This is the end of range function lesson See you in our next lessons In [ ]: The Complete Python Programming Course: (Beginner to Advanced) ... print( *range( 20,0)) #countdown In [12]: print( *range( 15,0,-1)) # countdown 15 to 15 14 13 12 11 10 In [13]: for i in range( 0,20): print(i) 10 11 12 13 14 15 16 17 18 19 In [14]: for i in range( 1,10,):...In [9]: print( *range( 1,99,3)) #step size 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 91 94 97 In [10]: print( *range( 0,40,5)) #step size 5 10... for i in range( 10,0,-1): print(i * "+") ++++++++++ +++++++++ ++++++++ +++++++ ++++++ +++++ ++++ +++ ++ + The Complete Python Programming Course: (Beginner to Advanced) In [16]: for i in range( 10,0,-1):

Ngày đăng: 17/11/2019, 07:34

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan