Python_输入

n = input("请输入一个整数:") # 括号内的内容会打印在屏幕上
>>> n = input('please keyin:')
please keyin:

# input()输入默认为字符串类型,如果输入为数字需要进行转换
n = int(input()) #整型
n = float(input()) #浮点型
n = eval(input()) #根据实际情况决定n的类型

#有多个数据时可以用map函数接收(明确变量个数时)
>>> a, b, c = map(int, input().split()) # split()默认以空格分离
1 2 3
>>> a, b, c
(1, 2, 3)

>>> a, b, c = map(float, input().split())
1 1.1 1.2
>>> a, b, c
(1.0, 1.1, 1.2)

>>> a, b, c = map(eval, input().split(','))
1,2.2,3
>>> a,b,c
(1, 2.2, 3)

>>> a, b, c = map(str, input().split())
sdf sdf se
>>> a,b,c
('sdf', 'sdf', 'se')

# 当不清楚变量个数时,用list
>>> a = list(map(eval, input().split(', ')))
3, 4, 4.4, 6.6
>>> a
[3, 4, 4.4, 6.6]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值