我是Python新手并尝试玩python挑战。在第2级,代码是:
enter image description here
我不明白string.ascii_lowercase[2:] + string.ascii_lowercase[:2]
的含义。我也在官方文件中找不到它。
答案 0 :(得分:1)
当分步完成时,也许最好解释一下:
>>> import string
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
>>> string.ascii_lowercase[:2] # Take the first two items from the string
'ab'
>>> string.ascii_lowercase[2:] # Take everything starting by the third item
'cdefghijklmnopqrstuvwxyz'
>>> string.ascii_lowercase[2:] + string.ascii_lowercase[:2] # concatenate them
'cdefghijklmnopqrstuvwxyzab'