Are def() important ?
Hello I am doing exercise that I found on pynative.com Basic thing, the last one being to take a string and make a new string with all the elements with an odd index. Doing the exercises is fun but each time I look at the solution, they are using def() for their solution. Like today my solution : #Question 3: Accept string from the user and display only those characters which are present at an even index x = input('enter string') d = list(x) y = [] for i,j in enumerate(x): if i%2 != 0: y.append(j) print(f"{''.join(y)}") the official solution def printEveIndexChar(str): for i in range(0, len(str)-1, 2): print("index[",i,"]", str[i] ) inputStr = input("Enter String ") print("Orginal String is ", inputStr) print("Printing only even index chars") printEveIndexChar(inputStr) Why are they using def() all the time. Is this just the way this coder like to proceed, or is it a good habit to take for the future when you do bigger projects?