Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

WHAT IS THE "LEN" AND "RANGE" FUNCTIONS DOING HERE ACTUALLY?

I am new to python and can not understand one thing in this code below:

def big_letter(text):
  for i in range(len(text)):
    text[i]= text[i].title()

names = ['nick', 'john', 'hugh', 'tony']
big_letter(names)
print(names)

WHAT IS THE "LEN" AND "RANGE" FUNCTIONS DOING HERE ACTUALLY?

I tried to manage things by deleting them in this code. They have some cost here but can not understand what exactly they did.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

So, I believe this code is trying to convert all the contents of the names list to title case. Explanation of code:

def big_letter(text):
    for i in range(len(text)):# start a loop that runs for the length of list text
                              # basically trying to cycle through the elements of 
                              # the list one by one
        text[i]= text[i].title() # converting each element to title case and 
                                 # assigning them to the list
        # print(text)        # I have added this. uncomment to see the process

names = ['nick', 'john', 'hugh', 'tony']
big_letter(names)           # Calling the function while passing the parameter
print(names)                # printing the list
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading