Python列表

107 阅读1分钟

Python列表
创建一个listletter的列表,里面装有元素 a ,b ,c ,d

1、赋值 ‘变量’ (关于赋值变量 参考文章 : blog.csdn.net/qq_36051316…

2、将两个变量相加并 ‘赋值’ 到一个新的变量(关于赋值变量 参考文章:blog.csdn.net/qq_36051316…

3、得到结果并 ‘输出’ 变量(关于输出 参考文章:blog.csdn.net/qq_36051316…

4、关于使用PyCharm 这个开发工具 , 产考文章:blog.csdn.net/qq_36051316…

listletter = ["a", "b", "c", "d"];

关于打印输出

# -*- coding: UTF-8 -*-
#创建一个listletter的列表,里面装有元素 a ,b ,c ,d
listletter = ["a", "b", "c", "d"];
print("第一次打印输出:")
for a in listletter:#循环后的结果:a b c d
    print(a,end=" ")#输出
# 如果要插入元素
print("")#换行
listletter.append("e");#循环后的结果:a b c d e
print("第二次打印输出:")
for a in listletter:
    print(a,end=" ")#输出
#如果要插入在前面的话,我们可以按索引插入
#那么什么是索引呢?listletter这个列表里面就是有 a b c d e 这5个元素,那么a对应的就是0,b对应的就是1
#所以我们用
print("")#换行
print("第三次打印输出:")
listletter.insert(0,"f")
for a in listletter:#循环后的结果:f a b c d e
    print(a,end=" ")#输出
print("")#换行