lists

Estimated reading time: 1 minute

lists

  • []
  • accept number,string,letter,nested list

list

price = [1,2,3]
print(price)
# [1,2,3]
print(len(price))
# 3

combine

price = [1,2,3]
numbers = [4,5,6]
total = price + numbers
print(total)
# [1, 2, 3, 4, 5, 6]

extend

append

slice

price = [1, 2, 3, 4, 5, 6]
print(price[1]) # 1
print(price[2:]) # [3, 4, 5, 6]
print(price[2:4]) # [3, 4]
print(price[2:-1]) # [3, 4, 5]
python