开发者

Split string into different variables instead of array in Python [duplicate]

This question al开发者_开发知识库ready has answers here: Closed 11 years ago.

The community reviewed whether to reopen this question 1 year ago and left it closed:

Original close reason(s) were not resolved

Possible Duplicate:

Python Split String

Is possible to directly split string into variables in one line, instead of using two lines. I'm sure that split would have two elements. Two lines example:

myString = "Anonym Anonymous"
a = myString.split()
firstName,lastName = a[0],a[1]


firstName, lastName = myString.split() should do it if you're sure it will return 2.

Better is firstName, lastName = myString.split(' ', 1)


firstname, lastname = "Anonym Anonymous".split()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜