蓝桥杯抱佛脚篇~

文章目录

基础语法

输入输出

python 复制代码
# 输入一个数
n=int(input())

# 输入两、三个数,例如:1 2 或者 1 2 3
x,y = map(int,input().split())

# 输入数组
# --------- 1 ------
nums=[int(i) for i in input().split()]
print(nums[1])
# --------- 2 ---------
c = list(map(int,input().split()))
print(c)

# 保留两位小数
x = 3.1415926
# 方法1:round()函数
print(round(x, 2))
# 方法2
a=3.14159265
print("%.2f"%a) # 这个自带四舍五入

# 输入二维数组
# --------- 1 ---------
nums=[]
for i in range(n):
  a,b=map(int,input().split())
  nums.append([a,b])
# --------- 2 ---------
nums = []
num = []
n = int(input())
for i in range(n):
    num=list(map(int,input().split()))
    nums.append(num)
print(nums[1][1])

# 无穷大的表示
INF=float('inf')

# 输入字符串
b = str(input())
print(b[1])

# 输出之间用空格隔开
# --------- 1 ---------
a=[1,2,3,4]
print(" ".join(map(str,a)))
# --------- 2 ---------
a=[1,2,3,4]
for i in a:
    print(str(i)+" ",end='')

# 用format函数(格式化字符串)输出多个值
print("{} + {} = {}".format(a,b,a+b))

集合(set)

集合是无序的、不重复的元素集合。以下是关于集合操作的示例:

python 复制代码
# 输入
s = set(input().split())
print(s)

# 添加元素
s.add(5)

# 删除元素
s.remove(1)

排序

例2: 使用列表的sort()方法进行排序

python 复制代码
nums = [3, 1, 4, 1, 5, 9, 2]
nums.sort()

print(nums)  # 输出: [1, 1, 2, 3, 4, 5, 9

例3: 对字符串进行排序

python 复制代码
text = "algorithm"
sorted_text = sorted(text)

print("".join(sorted_text))  # 输出: "aghilmort"
相关推荐
DBA_G4 小时前
南大通用GBase HD数据平台讲解
数据库
foolishlee5 小时前
Neon wal日志处理流程
数据库
星马梦缘5 小时前
数据库 事务管理 专项作战记录
数据库
名字还没想好☜5 小时前
Python concurrent.futures 实战:用 ThreadPoolExecutor 并发处理 + as_completed 收结果
数据库·python·php·并发
空杆推不起5 小时前
穿透数据库 JOIN 核心:语法分类、底层算法、生产优化与高频坑点全解析
数据库·oracle
xqqxqxxq6 小时前
MySQL 数据类型笔记
数据库·笔记·mysql
Logintern096 小时前
理解MySQL数据库的“事务与锁”
数据库·mysql
菜小麒6 小时前
面试问题-01
面试·职场和发展
朱容zr3331336 小时前
为什么推荐使用自增主键?使用UUID作为主键的优缺点是什么?
java·运维·数据库·后端·mysql·面试·性能优化
麻瓜code7 小时前
【Redis 】数据类型、持久化与过期删除
数据库·redis·缓存