当前位置:网站首页>使用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前面加中括号。本文仅介绍了一种方法,在此抛砖引玉,欢迎同学们分享其他方法。
边栏推荐
- 手写一个的在线聊天系统(原理篇1)
- Test 1234
- Self-supervised Heterogeneous Graph Neural Network with Co-contrastive Learning 论文阅读
- SQL injection - access injection, access offset injection
- 随着MapReduce job实现去加重,多种输出文件夹
- 同宇新材冲刺深交所:年营收9.47亿 张驰与苏世国为实控人
- AcWing 3537. Tree lookup complete binary tree
- 深度循环网络长期血压预测【翻译】
- 一种用于夜间和无袖测量血压手臂可穿戴设备【翻译】
- CSRF漏洞分析
猜你喜欢

287. Find duplicates

Why does wechat use SQLite to save chat records?

Penetration test information collection - WAF identification

Excellent open source fonts for programmers

Hongke shares | plate by plate ar application in Beijing Winter Olympics

Splay

美庐生物IPO被终止:年营收3.85亿 陈林为实控人
![[Matlab] Simulink 同一模块的输入输出的变量不能同名](/img/99/adfe50075010916439cd053b8f04c7.png)
[Matlab] Simulink 同一模块的输入输出的变量不能同名

被疫情占据的上半年,你还好么?| 2022年中总结

Summary of performance knowledge points
随机推荐
Describe the process of key exchange
Maixll-Dock 摄像头使用
安装及管理程序
Interpreting cloud native technology
AvL树的实现
阿里云国际版ECS云服务器无法登录宝塔面板控制台
node の SQLite
Deep circulation network long-term blood pressure prediction [translation]
朗坤智慧冲刺科创板:年营收4亿 拟募资7亿
Jdbc driver, c3p0, druid and jdbctemplate dependent jar packages
On AAE
STM32+ENC28J60+UIP协议栈实现WEB服务器示例
Stm32+hc05 serial port Bluetooth design simple Bluetooth speaker
AcWing 3537.树查找 完全二叉树
抽象类与抽象方法
MySQL查询请求的执行过程——底层原理
徐翔妻子应莹回应“股评”:自己写的!
Alibaba cloud international ECS cannot log in to the pagoda panel console
根据PPG估算血压利用频谱谱-时间深度神经网络【翻】
Echart simple component packaging