zoukankan      html  css  js  c++  java
  • python中append、extend、和insert的区别

    a_list = [x for x in range(1, 11)]
    print(a_list)
    a_list.append('sdadfewf')  # 将整个字符串放到列表的最后
    print(a_list)
    # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'sdadfewf']
    
    b_list = [x for x in range(1, 11)]
    print(b_list)
    b_list.extend('sdadfewf')  # 将字符串中的每个元素放到列表的最后
    print(b_list)
    # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 's', 'd', 'a', 'd', 'f', 'e', 'w', 'f']
    
    c_list = [x for x in range(1, 11)]
    print(c_list)
    c_list.insert(3, 'sdadfewf')  # 将整个字符串插入到列表索引为3的位置
    print(c_list)
    # [1, 2, 3, 'sdadfewf', 4, 5, 6, 7, 8, 9, 10]
  • 相关阅读:
    algorithm
    jstl
    jsp
    cookie
    变量和方法调用过程中会出现的参数传递
    http请求
    weblogic 的安全域问题
    web service
    行业充电
    客户端生成web service
  • 原文地址:https://www.cnblogs.com/yang901112/p/11311793.html
Copyright © 2011-2022 走看看