我想要这个结果,但不是通过字符串,通过input()和未知字符数!
mystring = 'abcd'
for a in (mystring[0].upper(), mystring[0].lower()):
for b in (mystring[1].upper(), mystring[1].lower()):
for c in (mystring[2].upper(), mystring[2].lower()):
for d in (mystring[3].upper(), mystring[3].lower()):
print(a+b+c+d)
使用swapcase
和itertools.permutation的一种方法:
from itertools import product
mystring = 'abcd'
cases = zip(*[mystring, mystring.swapcase()])
for permutation in product(*cases):
print("".join(permutation))
abcd
abcD
abCd
abCD
aBcd
aBcD
aBCd
aBCD
Abcd
AbcD
AbCd
AbCD
ABcd
ABcD
ABCd
ABCD