python-demo/basic_learn/列表.py

27 lines
462 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@File : 列表.py
@Author : lichao
@Date : 2024/11/26 17:06
@Software : PyCharm
"""
# 创建列表的两种方式
# 1.使用[]创建
list1 = [1,2,3,4,5]
list1.append(6)
# 2.使用list()创建
list2 = list('hello')
print(list1,list2)
# 3.使用+ 连接两个列表
list3 = list1 + list2
print(list3)
# 使用 + 不改变原列表, 使用+= 更改原列表
# 使用append()改变原列表