当前位置:网站首页>使用map函数、split函数一行键入多个元素
使用map函数、split函数一行键入多个元素
2022-07-06 10:52:00 【算法与编程之美】
如何解决题目要求一行同时输入两个或者两个以上未知数的问题。
1 问题
在目前的学习中,我们遇到过一些题目要求一行同时输入两个或者两个以上的未知数,但是我们学过的input函数难以解决问题。
2 方法
首先,我们从键盘上输入需要同时输入的未知数名,再利用map函数加input函数再加split函数定义需要键入的未知数。
3 实验结果与讨论
通过实验、实践等证明提出的方法是有效的,是能够解决开头提出的问题。
代码清单 1
| num1,num2 = map(int,input().split()) #split后接的括号里面是空的,所以等下用空格分隔,如果用split(“,”),那么就是用逗号分隔 print(num1,num2) |
4 结语
本文主要介绍了利用map函数、split函数解决同时键入多个数的办法,另外,若是想要直接将键入的数加入列表,可以在map前面加中括号。本文仅介绍了一种方法,在此抛砖引玉,欢迎同学们分享其他方法。
边栏推荐
- Breadth first traversal of graph
- Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
- Jushan database was among the first batch of financial information innovation solutions!
- 上海部分招工市场对新冠阳性康复者拒绝招录
- 用于远程医疗的无创、无袖带血压测量【翻译】
- 文档编辑之markdown语法(typora)
- Test 123
- [Matlab] Simulink 同一模块的输入输出的变量不能同名
- Stm32+esp8266+mqtt protocol connects onenet IOT platform
- Celery best practices
猜你喜欢

None of the strongest kings in the monitoring industry!

朗坤智慧冲刺科创板:年营收4亿 拟募资7亿

Excellent open source fonts for programmers

Maixll-Dock 摄像头使用

Numerical analysis: least squares and ridge regression (pytoch Implementation)

视频化全链路智能上云?一文详解什么是阿里云视频云「智能媒体生产」

监控界的最强王者,没有之一!

Coco2017 dataset usage (brief introduction)

测试行业的小伙伴,有问题可以找我哈。菜鸟一枚~

CSRF vulnerability analysis
随机推荐
解读云原生技术
Self supervised heterogeneous graph neural network with CO comparative learning
Docker安装Redis
wx小程序学习笔记day01
AFNetworking框架_上传文件或图像server
celery最佳实践
测试123
Afnetworking framework_ Upload file or image server
How does crmeb mall system help marketing?
根据PPG估算血压利用频谱谱-时间深度神经网络【翻】
STM32+ENC28J60+UIP协议栈实现WEB服务器示例
node の SQLite
[the 300th weekly match of leetcode]
Optical blood pressure estimation based on PPG and FFT neural network [translation]
Penetration test information collection - WAF identification
具体说明 Flume介绍、安装和配置
测试1234
Cocos2d Lua smaller and smaller sample memory game
2022/02/12
徐翔妻子应莹回应“股评”:自己写的!