算法笔试过程中的几个输入输出python语句


title: python在线笔试学习笔记
localimage: image1
urlname: writenexam
categories:
summary
tags: [writen, exam]
date: 2019-9-17 10:00:00

摘要

本文主要介绍一些算法笔试过程中的几个输入输出python语句的代码格式

  • [x] Edit By Porter, 积水成渊,蛟龙生焉。

字符串型

单行输入

import sys
line = sys.stdin.readline().strip()
print(line)#输出的字符串

多行输入

import sys
if __name__ == "__main__":
    data=[]
while True:
    line = sys.stdin.readline().strip()
    if not line:
        break
    data.append(line)
print("-".join(data))
 
比如输入
1
 
2
 
3
输出:1-2-3

数值型

输入数字

n=int(input())
print(n)#输出为数字

单行输入输出为数组

l=list(map(int,input().split(" ")))
print(l)

输出形式为矩阵

import sys
if __name__ == "__main__":
    data=[]
while True:
    line = sys.stdin.readline().strip()
    if not line:
        break
    tmp = list(map(int, line.split(" ")))
    data.append(tmp)
print(data)
原文地址:https://www.cnblogs.com/pertor/p/11634130.html