Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using string.capwords - Explained solution in Clear category for Conversion into CamelCase by Selindian
import string
def to_camel_case(name: str) -> str:
# Use capwords from string split string by '_' and capitalise all slices. Then replace '_' with nothing.
return string.capwords(name, sep='_').replace('_', '')
if __name__ == '__main__':
print("Example:")
print(to_camel_case('name'))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert to_camel_case("my_function_name") == "MyFunctionName"
assert to_camel_case("i_phone") == "IPhone"
assert to_camel_case("this_function_is_empty") == "ThisFunctionIsEmpty"
assert to_camel_case("name") == "Name"
print("Coding complete? Click 'Check' to earn cool rewards!")
March 29, 2022