Question

Python The capitalize function should receive a word as a parameter in the form of a...

Python

The capitalize function should receive a word as a parameter in the form of a string and return one
version where the first character is written in capital letters. Other characters must be unchanged. For example
‘hey’ become ‘Hey’. Write the function clearly. Consider that str has the method upper that returns
a new string where all characters are capitalized

Homework Answers

Answer #1

capitalize function:

def capitalize(str):
    return str.upper()[0]+str[1:]

str.upper() returns the string with all the uppercase characters. using [0] we fetch the first character of that uppercased string. In this character, we add the rest of the characters of str starting from index 1 to end. This is done using str[1:].

To test this function, we can write the following lines:

result = capitalize("hey")
print(result)

Sample Output:

Refer the following screenshot for indentation and overall idea:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
using the python Write a function oneSpaceAfterPeriod( String Parameter ) that will return a string with...
using the python Write a function oneSpaceAfterPeriod( String Parameter ) that will return a string with one space after every period. Another function twoSpaceAfterPeriod (String Parameter) that will return a string with two spaces after every period. It is also a common error to forget to capitalize the first word after a period. Write a function to correct this and return the corrected paragraph.
Use C language    bool isupper(char c): This function returns true if the character in c is...
Use C language    bool isupper(char c): This function returns true if the character in c is an uppercase character between A and Z (inclusive). Note that the C standard library function isupper() both accepts and returns an int, not char or bool, but the behavior is equivalent.     void strlower(char str[]): Change all uppercase ASCII characters in the C string str to their lowercase equivalents. For example, A would become a, and G would become g. All other characters in...
Write a Python function that takes a filename as a parameter and returns the string 'rows'...
Write a Python function that takes a filename as a parameter and returns the string 'rows' if a file was written row by row, and 'columns' if the file was written column by column. You would call the function with a command like filetype = myfunc(filename).
Write a function called score that meets the specifications below. def score(word, f): """ word, a...
Write a function called score that meets the specifications below. def score(word, f): """ word, a string of length > 1 of alphabetical characters (upper and lowercase) f, a function that takes in two int arguments and returns an int Returns the score of word as defined by the method: 1) Score for each letter is its location in the alphabet (a=1 ... z=26) times its distance from start of word. Ex. the scores for the letters in 'adD' are...
Python The function cube should receive a list as a parameter and return a new list...
Python The function cube should receive a list as a parameter and return a new list with each number taken in cubic (raised to three). Write the necessary code for the function, as well as an example which uses the function to calculate and print the cubes for the numbers 5, 8 and 9
Write a function named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "i" replaced with the character "n python
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first, third, fifth (and so on) characters of the strings, with each character both preceded and followed by the ^ symbol, and with a newline appearing after the last ^ symbol. The function returns no value; its goal is to print its output, but not to return it. Q2) Write a Python function called lines_of_code that takes a Path object as a parameter, which is...
Write a Python function that computes the frequency of characters in a string s. The function...
Write a Python function that computes the frequency of characters in a string s. The function should return a map where the key is the character and the value is the count. Make sure you include a main function and include comments to document your code.
Write a Python function first_chars that takes one parameter, which is a nested list of strings....
Write a Python function first_chars that takes one parameter, which is a nested list of strings. It returns a string containing the first character of all of the non-empty strings (at whatever depth they occur in the nested list) concatenated together. Here are a couple of examples of how the function should behave when you're done: >>> first_chars(['Boo', 'is', 'happy', 'today']) 'Biht' >>>first_chars(['boo', 'was', ['sleeping', 'deeply'], 'that', 'night', ['as', ['usual']]]) 'bwsdtnau'
This is function.py def processString(string): # Implement this function This is # This should print 4.5...
This is function.py def processString(string): # Implement this function This is # This should print 4.5 3.0 processString("An example. Two") # This should print 4.4 5.3 4.5 processString("This is the first sentence. The second sentence starts after the period. Then a final sentence") Download function.py and complete the processString(string) function. This function takes in a string as a parameter and prints the average number of characters per word in each sentence in the string. Print the average character count per...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT