python--交换变量

x = input('输入 x 值:')
y = input('输入 y 值:')
# 创建临时变量
temp = x
x = y
y = temp
print('交换后x的值为:{}'.format(x), "\n", '交换后y的值为:{}'.format(y))
# 不使用临时变量
x = input('输入 x 值:')
y = input('输入 y 值:')
x, y = y, x
print('交换后x的值为:{}'.format(x), "\n", '交换后y的值为:{}'.format(y))

猜你喜欢

转载自blog.csdn.net/weixin_55821558/article/details/124529476
今日推荐