กลับมาเมื่อธาตุอยู่ในรายชื่อ

รหัสตัวอย่าง

110
0

ปลั๊กอินสำหรับไพธอนสุดท้ายธาตุอยู่ในรายชื่อ

# To get the last element in a list you use -1 as position
bikes = ['trek', 'redline', 'giant']
bikes[-1]
# Output:
# 'giant'
2
0

ปลั๊กอินสำหรับไพธอนขวานไปรอบสุดท้ายธาตุอยู่ในรายชื่อ

some_list = [1, 2, 3]
some_list[-1]
print(some_list)
#Output = 3
1
0

เมื่อค่าต่างๆภาษาไพธอน

list[-1]
1
0

ปลั๊กอินสำหรับไพธอนรายการสุดท้ายธาตุ

my_list = ['red', 'blue', 'green']
# Get the last item with brute force using len
last_item = my_list[len(my_list) - 1]
# Remove the last item from the list using pop
last_item = my_list.pop() 
# Get the last item using negative indices *preferred & quickest method*
last_item = my_list[-1]
# Get the last item using iterable unpacking
*_, last_item = my_list

หน้าคล้ายกัน

คล้ายกันหน้ากับตัวอย่าง

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังหน้ากับตัวอย่างอยู่ในหมวดหมู่