Randomly capitalize letters in string [duplicate]
问题 This question already has answers here : How do I modify a single character in a string, in Python? (4 answers) Closed 2 years ago . I want to randomly capitalize or lowercase each letter in a string. I'm new to working with strings in python, but I think because strings are immutable that I can't do the following: i =0 for c in sentence: case = random.randint(0,1) print("case = ", case) if case == 0: print("here0") sentence[i] = sentence[i].lower() else: print("here1") sentence[i] = sentence