当前位置:网站首页>使用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前面加中括号。本文仅介绍了一种方法,在此抛砖引玉,欢迎同学们分享其他方法。
边栏推荐
猜你喜欢

小程序在产业互联网中的作用

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

Docker安装Redis

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

On AAE

wx小程序学习笔记day01

Medical image segmentation
![Optical blood pressure estimation based on PPG and FFT neural network [translation]](/img/88/2345dac73248a5f0f9fa3142ca0397.png)
Optical blood pressure estimation based on PPG and FFT neural network [translation]
![Deep circulation network long-term blood pressure prediction [translation]](/img/9c/c1ed28242a4536c1e8fde3414f82a8.png)
Deep circulation network long-term blood pressure prediction [translation]

None of the strongest kings in the monitoring industry!
随机推荐
Using block to realize the traditional values between two pages
Epoll () whether it involves wait queue analysis
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
Numerical analysis: least squares and ridge regression (pytoch Implementation)
node の SQLite
Method of accessing mobile phone storage location permission under non root condition
Markdown syntax for document editing (typera)
Brief description of SQL optimization problems
Huawei 0 foundation - image sorting
C#/VB.NET 给PDF文档添加文本/图像水印
MySQL查询请求的执行过程——底层原理
重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
【LeetCode第 300 场周赛】
美庐生物IPO被终止:年营收3.85亿 陈林为实控人
Afnetworking framework_ Upload file or image server
Summary of performance knowledge points
使用cpolar建立一个商业网站(1)
Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
On AAE
First, look at K, an ugly number