当前位置:网站首页>使用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前面加中括号。本文仅介绍了一种方法,在此抛砖引玉,欢迎同学们分享其他方法。
边栏推荐
- Afnetworking framework_ Upload file or image server
- Breadth first traversal of graph
- UFIDA OA vulnerability learning - ncfindweb directory traversal vulnerability
- 使用cpolar建立一个商业网站(1)
- node の SQLite
- POJ 2208 six lengths of tetrahedron are known, and the volume is calculated
- MySQL查询请求的执行过程——底层原理
- Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
- STM32+HC05串口蓝牙设计简易的蓝牙音箱
- AvL树的实现
猜你喜欢

Method of accessing mobile phone storage location permission under non root condition

287. 寻找重复数

【中山大学】考研初试复试资料分享

Solve DoS attack production cases

Breadth first traversal of graph

Mathematics in machine learning -- common probability distribution (XIII): Logistic Distribution

2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目

Medical image segmentation

Tree-LSTM的一些理解以及DGL代码实现

Describe the process of key exchange
随机推荐
wx小程序学习笔记day01
Breadth first traversal of graph
裕太微冲刺科创板:拟募资13亿 华为与小米基金是股东
SQL优化问题的简述
STM32+MFRC522完成IC卡号读取、密码修改、数据读写
Estimate blood pressure according to PPG using spectral spectrum time depth neural network [turn]
线代笔记....
Jdbc driver, c3p0, druid and jdbctemplate dependent jar packages
win10系统下插入U盘有声音提示却不显示盘符
DOM简要
Epoll () whether it involves wait queue analysis
AcWing 3537. Tree lookup complete binary tree
Penetration test information collection - site architecture and construction
Specify flume introduction, installation and configuration
[Sun Yat sen University] information sharing of postgraduate entrance examination and re examination
SQL injection - access injection, access offset injection
Automatic reservation of air tickets in C language
监控界的最强王者,没有之一!
Penetration test information collection - App information
具体说明 Flume介绍、安装和配置