how are functions defined in python ?

Answer Posted / chaitu

# Defines a "repeat" function that takes 2 arguments.

def repeat(s, exclaim):

"""

Returns the string 's' repeated 3 times.

If exclaim is true, add exclamation marks.

"""

result = s + s + s

if exclaim:

result = result + '!!!'

return result

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Given a N by N matrix of both negative and positive integers. Write an efficient algorithm to find the sub-matrix with the largest sum of all the contained elements.

1289


Write a python program to count the number of vowels in a string?

499


Write a python program to check if a number is a perfect number?

503


Write a python program to check if a string is a palindrome or not?

494


Write a python program to check common letters in two input strings?

484






Write a function that takes an array of integers and returns that array rotated by N positions. For example, if N=2, given the input array [1, 2, 3, 4, 5, 6] the function should return [5, 6, 1, 2, 3, 4]

1852


How to print sum of the numbers starting from 1 to 100?

444


Write a python program to check if a number is a palindrome or not?

447


Write a function to efficiently convert a floating point number to a rational number. For example, given 0.125 return "1/8"

1174


Write a python program to check if a number is an armstrong number?

465


What is the output when we execute list(“hello”)?

624


Write a python program to find the second largest number in a list?

479


Write a function that takes an integer and returns the smallest number that is greater than the given number which is a palendrome. For example, if the input was 111 the next palindromic number would be 121.

1400


plz tell me the exam date for clerks in sbi

1782


Write a python program to print table of a given number?

460