Python基础学习
今天遇到了的问题
Missing parentheses in call to ‘print‘
Python2和Python3不兼容原因Python3只能用
print(....)
str不是迭代器,不能直接用for循环,最佳处理办法是遍历索引
输入
 输入单个值
 int(input())
 确定个数的值
 a, b, c = map(int, input().split())
 未知个数的一行(一维数组)
 arr = list(map(int, input().split()))
 arr = list(int(i) for i in input().split())
int(i) for i in input().split()
[expression for iter_val in iterable if condition]列表解析
map(int, input().split())
map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回。
map(func, Iist)
二维数组输入
n = int(input())
arr = []
for i in range(n) :
    arr.append(list(map(int, input().split())))
未声明有终止的输入
import sys
for n in sys.stdin:
	if n == '\n'
		break
	print(n)
更好的写法
try:
    while True:
        s = input()
except:
    pass
输出格式
- 四舍五入保留两位小数
 “{:.2f}”.format(math.pi)
 round(v, 2)
 ‘%.2f’ %(v)
- 保留两位小数
 a = str(v).split(‘.’)
 a[0] + a[1][:3]

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号