当前位置:网站首页>使用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前面加中括号。本文仅介绍了一种方法,在此抛砖引玉,欢迎同学们分享其他方法。
边栏推荐
- Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
- POJ 2208 已知边四面体六个长度,计算体积
- How does crmeb mall system help marketing?
- JDBC驱动器、C3P0、Druid和JDBCTemplate相关依赖jar包
- 简单易用的PDF转SVG程序
- Cocos2d Lua smaller and smaller sample memory game
- This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer
- 图片缩放中心
- 监控界的最强王者,没有之一!
- STM32+HC05串口蓝牙设计简易的蓝牙音箱
猜你喜欢

裕太微冲刺科创板:拟募资13亿 华为与小米基金是股东

Visual Studio Code启动时提示“Code安装似乎损坏。请重新安装。”、标题栏显示“不受支持”信息的解决办法

简单易用的PDF转SVG程序

Top command details
![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]

Blue Bridge Cup real question: one question with clear code, master three codes

二叉搜索树

Execution process of MySQL query request - underlying principle

【LeetCode第 300 场周赛】

被疫情占据的上半年,你还好么?| 2022年中总结
随机推荐
The role of applet in industrial Internet
使用cpolar建立一个商业网站(1)
There is a sound prompt when inserting a USB flash disk under win10 system, but the drive letter is not displayed
44 colleges and universities were selected! Publicity of distributed intelligent computing project list
RedisSystemException:WRONGTYPE Operation against a key holding the wrong kind of value
SAP Fiori 应用索引大全工具和 SAP Fiori Tools 的使用介绍
Execution process of MySQL query request - underlying principle
Splay
287. 寻找重复数
Celery best practices
DOM简要
POJ 2208 已知边四面体六个长度,计算体积
Some understandings of tree LSTM and DGL code implementation
Bonecp uses data sources
Self supervised heterogeneous graph neural network with CO comparative learning
Hongke shares | plate by plate ar application in Beijing Winter Olympics
Picture zoom Center
Visual Studio Code启动时提示“Code安装似乎损坏。请重新安装。”、标题栏显示“不受支持”信息的解决办法
监控界的最强王者,没有之一!
Docker installation redis