蓝桥杯抱佛脚篇~

文章目录

基础语法

输入输出

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"
相关推荐
AAA修煤气灶刘哥9 小时前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
RestCloud13 小时前
揭秘 CDC 技术:让数据库同步快人一步
数据库·api
得物技术16 小时前
MySQL单表为何别超2000万行?揭秘B+树与16KB页的生死博弈|得物技术
数据库·后端·mysql
可涵不会debug20 小时前
【IoTDB】时序数据库选型指南:工业大数据场景下的技术突围
数据库·时序数据库
ByteBlossom20 小时前
MySQL 面试场景题之如何处理 BLOB 和CLOB 数据类型?
数据库·mysql·面试
麦兜*21 小时前
MongoDB Atlas 云数据库实战:从零搭建全球多节点集群
java·数据库·spring boot·mongodb·spring·spring cloud
Slaughter信仰21 小时前
深入理解Java虚拟机:JVM高级特性与最佳实践(第3版)第十章知识点问答(10题)
java·jvm·数据库
麦兜*21 小时前
MongoDB 在物联网(IoT)中的应用:海量时序数据处理方案
java·数据库·spring boot·物联网·mongodb·spring
-Xie-21 小时前
Mysql杂志(十六)——缓存池
数据库·mysql·缓存