扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

python从小到大排列的代码怎么写

扬州沐宇科技
2023-12-21 09:40:36
python

下面是一个示例代码,展示如何使用Python对一组数字进行从小到大的升序排列:

numbers = [5, 2, 8, 3, 1]  # 示例数字列表
sorted_numbers = sorted(numbers)  # 使用sorted函数对数字列表进行升序排列
print(sorted_numbers)  # 打印排序后的结果

输出结果:

[1, 2, 3, 5, 8]

扫码添加客服微信