0% found this document useful (0 votes)
35 views3 pages

CH-9 Functions and String in Python (1)

The document explains the concept of functions in programming, defining them as reusable code blocks that perform specific tasks. It also covers strings as sequences of characters and details various types of functions, including built-in and user-defined functions, along with examples of string manipulation functions and operators in Python. Key components of a function, such as its name, arguments, statements, and return value, are also outlined.

Uploaded by

Atharva :D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

CH-9 Functions and String in Python (1)

The document explains the concept of functions in programming, defining them as reusable code blocks that perform specific tasks. It also covers strings as sequences of characters and details various types of functions, including built-in and user-defined functions, along with examples of string manipulation functions and operators in Python. Key components of a function, such as its name, arguments, statements, and return value, are also outlined.

Uploaded by

Atharva :D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Common Mistake

Strings a Text functions


Answer the following
Q1. What are functions?
Ans: - A function can be defined as a block of a reusable code that
performs a specific task. Functions help us to break our program into
smaller pieces or modules.
Q2. Define strings.
Ans: - A sequence of characters which is enclosed or surrounded by
single (‘ ’) or double (“ ”) quotes is known as a string. The sequence
may include a letter, number, special characters or a backslash.
Python treats single quotes as double quotes.
Q3. Write any two features of functions.
Ans: -Two features of functions are:
1. A program is divided into small modules and each module
performs some specific task. Each module can be called as per the
requirement.
2. We can call a function as many times as required. This saves the
programmer the time and effort to rewrite the same code again.
Therefore, it also reduces the length of the program.
Q4. Write the components of a function.
Ans: - A Python function consists of the following components:
Name of the function: A function name should be unique and easy
to correlate with the task it will perform. We can have functions of
the same name with different parameters.
Arguments: The input given to the functions are referred to as
arguments. A function can or cannot have any arguments.
Statements: The statements are the executable instructions that the
function can perform.
Return Value: A function may or may not return a value.
Q5. How can we call a function in Python?
Ans:- A function can be called anytime from other functions or from
the command prompt after the definition.
Q6. What are the different types of functions. Explain in detail.
Ans:- Built-In Functions: The print() and input() belong to the
category of built-in functions. We also have other built-in functions
like range(), type(), etc. The main difference between these two
categories is that built-in functions do not require to be written by us
whereas a user-defined function has to be developed by the user at
the time of writing a program.
User-Defined Functions: User-defined functions are created by the
user according to the need of the program. Once the user defines a
function, the user can call it in the same way as the built-in functions.
User-defined functions are divided into various categories based on
the parameters and return type.
Q7. Write the any two built-in-functions to manipulate strings.
Ans:- Two built-in functions to manipulate strings:
1. len(): The len() function calculates and returns the length of a
string supplied as an argument.
2. lower(): The lower() function converts all uppercase letters to
lowercase.
Q8. Explain about two basic String Operators in Python?
Ans: String Concatenation Operator (+): String concatenation
operator joins two or more strings into one.
Ex: s1=’my name is’
s2=’jacob’
s= s1 + s2
print(s)
O/P: my name isJacob
String Replication Operator (*): The replication operator is used to
repeat the string for a given number of times.
Ex: s1=’hello’
s= s1 * 3
print(s)
O/P: hello
Hello
hello

You might also like