0
我有以下代碼:等距印刷
for k in sorted(data):
print '%s:\t\t%s' % (k, data[k])
這對我來說會打印:
Date: 2016-03-05
NumMovieTerritories: 164
NumMovieTerritoriesLive: 111
NumMovieTitles: 115393
NumMovieTitlesLive: 103785
NumProviders: 1411
NumProvidersLive: 1136
NumTVTerritories: 36
NumTVTerritoriesLive: 6
NumTVTitles: 424321
NumTVTitlesLive: 392832
NumTerritoryAvails: 1837294
NumTerritoryAvailsLive: 1597407
我會怎麼做,使得打印象表的內容:
Date: 2016-03-05
NumMovieTerritories: 164
NumMovieTerritoriesLive: 111
NumMovieTitles: 115393
NumMovieTitlesLive: 103785
NumProviders: 1411
NumProvidersLive: 1136
NumTVTerritories: 36
NumTVTerritoriesLive: 6
NumTVTitles: 424321
NumTVTitlesLive: 392832
NumTerritoryAvails: 1837294
NumTerritoryAvailsLive: 1597407
能得到確切的格式,如果最後一行更改爲'打印( 「{} {} {}」。格式(K '' *(MAX_LENGTH - LEN(K) ),data [k]))'儘管學習'ljust()'很酷! – Mark