跳到正文

个人记录

A+B 最短代码

Cat_King约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前

众所周知, Python 是一门极精简的语言。而闲的没事热衷于挑战最短代码的我决定,写出最短 A+B 代码。

小试牛刀:

Python
x=input().split()
print(int(x[0])+int(x[1]))

45B ,中规中矩。

优化:

Python
x,y=input().split()
print(int(x)+int(y))

41B ,稍好一些。

使用表达式计算函数 eval 和字符替换:

Python
print(eval(input().replace(' ','+')))

37B ,并列第一!

但我们还能做的更好!

使用 sum 求和函数和 map 转序列类型函数:

Python
print(sum(map(int,input().split())))

36B ,成功拿下最短代码!

原文