本文目錄一覽:
python中pprint在哪個包
在pprint包中
import pprint
tup = (‘spam’, (‘eggs’, (‘lumberjack’, (‘knights’, (‘ni’, (‘dead’,
… (‘parrot’, (‘fresh fruit’,))))))))
stuff = [‘a’ * 10, tup, [‘a’ * 30, ‘b’ * 30], [‘c’ * 20, ‘d’ * 20]]
pprint.pprint(stuff)
[‘aaaaaaaaaa’,
(‘spam’,
(‘eggs’,
(‘lumberjack’,
(‘knights’, (‘ni’, (‘dead’, (‘parrot’, (‘fresh fruit’,)))))))),
[‘aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa’, ‘bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb’],
[‘cccccccccccccccccccc’, ‘dddddddddddddddddddd’]]
問道python題?
# encoding: utf-8
# Python 3.6.0
# 判斷輸入的兩個字元串在忽略大小寫和空格的情況下是否相同
s1=input(“請輸入第一行字元串:”)
s2=input(“請輸入第二行字元串:”)
s1=s1.upper().replace(‘ ‘,”)
s2=s2.upper().replace(‘ ‘,”)
if s1 == s2 :
print(‘YES’)
else:
print(‘No’)
python判斷讀取哪一行數據讀錯了?
for line in sj1:
這樣讀出來是沒有行號的。你可以在
res1 = re.search(patternPage, line, re.M|re.I)
後加上
if res1 is None:
….print(line)
這樣可以輸出出錯的行的內容
或者在for之前定義一個變數i_line=0
然後在for 里寫i_line=i_line+1再做正則判斷,出錯時輸出i_line即為行號
i_line=0
for line in sj1:
….i_line=i_line+1
….res1 = re.search(patternPage, line, re.M|re.I)
….if res1 is None:
……..print(f’ERROR: not patternPage at (line {i_line}): {line}’)
……..continue
….l = int(res1.group(1))
原創文章,作者:簡單一點,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/130603.html