Python包含特殊字符的输入问题
1.当输入的格式既包含空格又包含逗号时,如:
“ 123, 5”
简单使用Input.()将会把所以内容视为字符串。
可以先用
a, b = input().split(",")
# 以“,”为分隔符分别将数据存入变量中
再用
c, d = a.strip(), b.strip()
就得到了单个的字符'123'和'5'
2.数字以空格隔开的
(1).使用map函数
a,b,c = map(int,input().split())
或
nums = list(map(int, str.strip().split())
str是接收的字符串
(2)先以字符串str接收,再利用num列表
num = [int(n) for n in str.split()]