python basics - tuples

########################################################################

# Tuple, elements cannot be modified, added or deleted
# tuple
# tu = (11,22,33,44)
# tu.count(22), get the number of times the specified element appears in the tuple
# tu.index (twenty two)

####################################### Dark Grey Magic######## #################
# 1. Writing format
  # tu = (111,"alex",(11,22),[(33,44)],True,33, 44,)
  # When writing a tuple, it is recommended to add it at the end,
  # Elements cannot be modified, added or deleted


# 2. Index
  # v = tu[0]
  # print(v)

# 3. Slice
  # v = tu[0:2]
  # print(v)

# 4. Can be for looped, iterable object
  # for item in tu:
  # print(item)

# 5. 转换
  # s = "asdfasdf0"
  # li = ["asdf","asdfasdf"]
  # tu = ("asdf","asdf")
  # v = tuple(s)
  # print(v)

  # v = tuple(li)
  # print(v)

  # v = list (tu)
  # print (v)

  # v = "_".join(tu)
  # print(v)

  # li = ["asdf","asdfasdf"]
  # li.extend((11,22,33,))
  # print(li)

# 6. The first-level elements of the tuple cannot be modified/deleted/added
  # tu = (111,"alex",(11,22),[(33,44)],True,33,44,)
  # tuple, in order.
  # v = tu[3][0][0]
  # print(v)
  # v=tu[3]
  # print(v)
  # tu[3][0] = 567
  # print(tu)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325080289&siteId=291194637