#NoPayJan Offer - Access all CloudxLab Courses for free between 1st to 31st JanEnroll Now >>
A string is a sequence of characters. For eg,
s = "Python"
To access a single character, we can use a bracket operator and an index,
c1 = s c2 = s
'y'. Index starts from
0 for a
str (or a list).
Indices must be integers. Try accessing a character using a non
int index and observe the error.
Length starts counting from
0. You can get the length of the string using
It gives the answer as
str_functhat takes one argument and returns the last character of the string passed to the function as a parameter.
sum_str_functhat takes one argument and returns the sum of all digits in that number. The argument passed can be
int. You need to convert the integer to a string to calculate it's length, and then use a loop to add each digit to calculate the sum of all digits.
No hints are availble for this assesment
Answer is not availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here