making first letter in string non capital in python

To make the first letter of a string lowercase in python, you can use the lower() method in combination with string slicing. Here's an example:

main.py
my_string = "Hello, World!"
new_string = my_string[0].lower() + my_string[1:]
print(new_string)  # Output: "hello, World!"
123 chars
4 lines

Alternatively, you can use the capitalize() method to capitalize the first letter of a string and convert the rest of the string to lowercase:

main.py
my_string = "Hello, World!"
new_string = my_string.capitalize()
print(new_string)  # Output: "Hello, world!"
109 chars
4 lines

Note that the upper() method can also be used to capitalize the first letter in a string, but it will also convert the rest of the string to uppercase:

main.py
my_string = "hello, world!"
new_string = my_string[0].upper() + my_string[1:]
print(new_string)  # Output: "Hello, world!"

new_string2 = my_string.upper()
print(new_string2)  # Output: "HELLO, WORLD!"
202 chars
7 lines

gistlibby LogSnag