The given question is (Given a string in camel case, write a python program to convert the given string from camel case to snake case.)
Given inputs
I need code and explanation for this question........?
# Camel word input
CamelStr = input('Enter a string in camel notation: ')
# Create an empty letter list of a word in snake notation
letters=[]
# We iterate through all the letters of the earlier
# entered word letter by letter
for letter in CamelStr:
# If an uppercase character is encountered, add _
if letter.isupper():
letters.append('_')
# Add small letters to the list
letters.append(letter.lower())
# If the initial character in the list is _ then remove it
if letters[0] == '_':
letters.pop(0)
# Convert the list to a string and print
snake_str =''.join(letters)
print(snake_str)
Comments
code working!!!
Leave a comment