当前位置:网站首页>Use map function and split function to type multiple elements in one line

Use map function and split function to type multiple elements in one line

2022-07-06 18:46:00 Beauty of algorithm and programming

How to solve the problem that requires two or more unknowns to be input in one line at the same time .

1 problem

In the current study , We have encountered some problems that require two or more unknowns to be entered in a row at the same time , But what we learned input Functions are difficult to solve .

2 Method

First , We input unknown names that need to be input at the same time from the keyboard , recycling map Function plus input Function plus split The function defines the unknowns that need to be typed .

3 Experimental results and discussion

Through the experiment 、 Practice has proved that the proposed method is effective , Is able to solve the problem raised at the beginning .

Code list 1

num1,num2 = map(int,input().split())  #split The following parentheses are empty , So wait, separate with spaces , If you use split(“,”), Then it is separated by commas
print(num1,num2)

4 Conclusion

This article mainly introduces the utilization map function 、split Function to solve the problem of typing multiple numbers at the same time , in addition , If you want to add the number you typed directly to the list , Can be in map Preceded by brackets . This article only introduces one method , Here's a good example , Welcome to share other methods .

原网站

版权声明
本文为[Beauty of algorithm and programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061051556494.html