可变类型与不可变类型;队列与堆栈

可变类型与不可变类型

不可变类型

s1 = '^^^^^success^^^^'
print(s1.strip('^'))  # success  本身并没有修改 是产生了新的结果
print(s1)  # ^^^^^success^^^^
# 查看内存地址
print(id(s1))  # 2168071404040
print(id(s1.strip('^')))  # 2168071377504

可变类型

s2 = [111, 222, 333]
print(s2.extend([11, 22, 33, 44, 55]))  # None 空
print(s2)  # [111, 222, 333, 11, 22, 33, 44, 55]
# 查看内存地址
print(id(s2))  # 1390036469896
s2.append(11111111)
print(id(s2))  # 1390036469896

队列与堆栈

队列

先进先出

new_list = []
# 先进
new_list.append('jack')
new_list.append('zoe')
new_list.append('lucas')
# 先出
# 方式一
for i in new_list:
    print(i)  # jack zoe lucas
# 方式二
print(new_list.pop(0))  # jack
print(new_list.pop(0))  # zoe
print(new_list.pop(0))  # lucas
图片名称

堆栈

先进后出

new_list = []
# 先进
new_list.append('jack')
new_list.append('zoe')
new_list.append('lucas')
# 后出
print(new_list.pop())  # lucas
print(new_list.pop())  # zoe
print(new_list.pop())  # jack
图片名称
posted @   一梦便是数千载  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示