Convert snake_case to camelCase in Python
Convert a snake_case string to camelCase.
IntermediateString ProgramsExample 25 of 25
convert-snake-case-to-camelcase.py
1# Program to convert snake_case to camelCase23snake = input("Enter snake_case string: ")45parts = snake.split("_")67if not parts:8 camel = ""9else:10 camel = parts[0].lower() + "".join(word.capitalize() for word in parts[1:])1112print("camelCase:", camel)
Output
Enter snake_case string: hello_world_example camelCase: helloWorldExample
What's going on
We split on underscores and capitalize each word after the first, then join them back.
After this program
If the idea is still fuzzy, read Day 4: Strings and String Methods in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 25 string programs, or see every topic on Python exercises.