Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 ruby 中,我可以执行以下操作:
key, *rest = ["key1", 1, 2, 3]
结果将是:
key = "key1" rest = [1, 2, 3]
有没有办法在 python 中做同样的事情?
key,rest = my_list[0],my_list[1:]
我认为尽可能接近(在 Python <= 2.7 中)。在 Python 3 中,您的代码按原样工作。