Pythone: 07 English text: read the contents of other constant exchange capitalization

# 2. Open an English text file, write a program to read its contents, and the uppercase and lowercase characters were interchangeable, other characters do not change
F2 = Open ( "test2.txt", "r")
contents2 = f2.readlines ()
Print (contents2)
f2.close ()
# result2 = []
# for STR in contents2:
# result2.append (str.swapcase ())
result2 = [str.swapcase () for STR in contents2]
Print (result2)
F2 = Open ( "is test2.txt", "W")
f2.writelines (result2)
f2.close ()

Published 172 original articles · won praise 442 · views 110 000 +

Guess you like

Origin blog.csdn.net/weixin_44015669/article/details/104101392