Functions in Python

Qus: What is a function? How is it useful?

A function is a named block in a program which has some certain working. Whenever you call this it performs all its working. It reduces the complexity and reduces the labour of writing same code again and again.

Qus: What is an argument? Give an example of one.

Ans : An argument is the requirement of a function to perform its working. For ex- pow(x,y), here x and y are the arguments which are required to pass to pow() for its working.

Qus. What is a string slice? How is it useful?

Ans: String Slice is a part of a string containing some contiguous characters from the string. It is accessed from the string by providing a range in ―[ ]‖ brackets i.e. S [n:m]. Python returns all the characters at indices n, n+1, n+2 . . . m-1 e.g. 'Barabanki'.[4:7] will return 'ban'.

Qus. Which functions would you chose to use to remove leading and trailing white spaces from a given string?

Ans: Python String strip() function will remove leading and trailing white spaces. If you want to remove only leading or trailing spaces, use lstrip() or rstrip() function instead.

Qus. Suggest appropriate functions for the following tasks –

(a) To check whether the string contains digits.

(b) To find the occurrence a string within another string.

(c) To convert the first letter of a string to upper case.

(d) To convert all the letters of a string to upper case.

(f) To check whether all the letters of the string are in capital letters.

(g) to remove all the white spaces from the beginning of a string.

Ans.  (a) isalnum() (b) find() (c) capitalize()   (d) upper() (f) isupper() (g) lstrip()


Programs

html program to display a table with 5 rows and 4 columns. Provide appropriate heading to the form

View Solution


HTML page to demonstrate target attribute in Frames

View Solution


HTML page to demonstrate a Clickable image

View Solution


HTML Page to display the following table

View Solution


design a html form using fieldset and legend

View Solution


JavaScript code that calculates the squares and cubes from 0 to 10

View Solution


AngularJS Program to find the Simple Interest

View Solution


Angular JS program to convert Temperature Fahrenheit to Degree Celsius

View Solution


AngularJS Program to change the background color of box

View Solution


AngularJS Program for Dollar to Indian Rupee Conversion

View Solution


Angular JS program to change the size of circle using range bar

View Solution


Presentation Lab Assignment 1

View Solution


Presentation Lab Assignment 2

View Solution


tkinter-program to create a registration form

View Solution


tkinter program to add two number

View Solution


gui program to connect database and store data

View Solution


django program Displaying Data from the Database

View Solution


tkinter program to calculate the simple intrest

View Solution


tkinter application to add delete todo list

View Solution


tkinter program to create drawing application

View Solution


tkinter program to create marksheet calculator

View Solution


tkinter program for temperature convertor

View Solution


CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad