Python字符串拆分

use*_*er1 2 python string hex

我需要采取六角对,例如7A,它破碎成7并A作为用于进一步操作单独的变量.分割这个字符串的正确方法是什么,因为我不是要删除任何字符,而且我没有任何分隔符?

Mar*_*oun 8

你可以使用list:

list('7A') 这将返回包含7和A的列表:

['7', 'A'] #Note that the single quote will not appear when you print the content :)
Run Code Online (Sandbox Code Playgroud)

(list('7A')[0]包含7并list('7A')[1]包含A)

或者通过:

[x for x in '7A']
Run Code Online (Sandbox Code Playgroud)

如果你的字符串中有超过2个字符并且你写了:

lst = list(youtString)
Run Code Online (Sandbox Code Playgroud)

然后lst将包含字符串的所有字符.