![](/img/trans.png)
[英]extracting particular number from a line consisting of several numbers using python
[英]How can I print a square consisting of numbers from 1 to 9 (from the example) using a 1 line code?
我需要在 1 行中編寫一個代碼,它將打印:
0123456789
1234567890
2345678901
3456789012
4567890123
5678901234
6789012345
7890123456
8901234567
9012345678
我這樣做了:
print([print(i) for i in range(10)])
但是這段代碼是完全錯誤的,輸出是:
0
1
2
3
4
5
6
7
8
9
[None, None, None, None, None, None, None, None, None, None]
我想我應該使用map()
和lambda
但我不知道該怎么做,我只是在學習...
print("\n".join([("".join(str((i+j)%10) for i in range(10))) for j in range(10)]))
請注意,打印函數返回None
這是你有原因None
印了這么多次,你需要嵌套循環打印此二維數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.