ARUNACHALA
ARTS & SCIENCE (WOMEN) COLLEGE
‘Kanakammal Gardens’,Vellichanthai,
Kanyakumari District - 629 203.
[Affiliated to Manonmaniam Sundaranar University, Tirunelveli.]
Department of Artificial Intelligence
Internal Examination-III
Programming with Python
Class: II [Link]. (AI) Date: 2025
[Link]
Duration:1Hrs
(2×1=2)
Part-A
I Choose the Correct Answer
1. What does it mean that Python strings are immutable?
a. You cannot create a string [Link] cannot delete a string once created
c. You cannot change the characters of a string after it is created
d. You can modify characters in a string using indexing
[Link] of the following methods is used to add an element at the end of a list?
a. insert() b. append() c. extend() d. add()
Part-B (2×5=10)
II Answer the following Questions
3. What is Keyword Argument? Explain with an example.
4. What are String operations in Python?
Part-C (1×8=8)
III Answer the following Question
5. Explain in detail about Bulit in String Methods and function?
Answer Key -Internal Exam III
Part-A
1. c) You cannot change the characters of a string after it is created
2.b) append()
Part-B
3. A keyword argument in Python is an argument passed to a function by explicitly specifying the
parameter name, instead of relying on its position.
This makes the function call more readable and allows arguments to be given in any order.
def student_info(name, age):
print("Name:", name)
print("Age:", age)
# Using keyword arguments
student_info(name="Alice",age=20)
Here, name="Alice" and age=20 are keyword arguments.
You specify the parameter name when calling the function.
Order doesn’t matter:
student_info(age=20,name="Alice")
This is still valid because the names identify the parameters.
4. In Python, string operations refer to the actions you can perform on str (string) objects—
Python’s type for handling text. Strings are immutable, meaning once created, they cannot be
changed, but you can create new strings based on operations.
Below are the most common string operations in Python:
1. Concatenation
Joining strings using +:
s1 = "Hello"
s2 = "World"
print(s1 + " " + s2) # Hello World
2. Repetition
Repeating a string using *:
print("Ha" * 3) # HaHaHa
3. Indexing
Accessing individual characters (zero-based indexing):
s = "Python"
print(s[0]) # P
print(s[-1]) # n
4. Slicing
Extracting substrings:
s = "Python"
print(s[0:3]) # Pyt
print(s[2:]) # thon
print(s[:4]) # Pyth
5. Length of a string
Using len():
len("Python") # 6
6. Membership testing
Check if a substring exists:
"Py" in "Python" # True
"Java" not in "Python" # True
7. String methods
Python provides many built-in methods:
"hello".upper() # "HELLO"
"WORLD".lower() # "world"
"python".capitalize() # "Python"
Part -C
5. Python provides many built-in string methods to manipulate and work with text.
All string methods return a new string because strings are immutable.
Methods are called using the dot (.) operator:
[Link]()
Python also has some built-in functions that work with strings (like len()).
1. Case Conversion Methods
upper()
Converts all characters to uppercase.
"hello".upper() # "HELLO"
lower()
Converts all characters to lowercase.
"HELLO".lower() # "hello"
capitalize()
Capitalizes first letter of the string.
"python programming".capitalize()
# "Python programming"
title()
Capitalizes the first letter of every word.
"hello world".title()
# "Hello World"
swapcase()
Swaps case of each character.
"Hello".swapcase()
# "hELLO"
casefold()
Aggressive lowercase conversion (for international languages).
"Ä".casefold()
2. Searching & Finding Methods
find()
Returns index of first occurrence; returns -1 if not found.
"hello".find("l") # 2
rfind()
Searches from right side.
"hello".rfind("l") # 3
index()
Same as find() but raises error if not found.
"hello".index("e") # 1
rindex()
Right-side version of index().
"hello".rindex("l") # 3
startswith() / endswith()
Checks prefix/suffix.
"python".startswith("py") # True
"python".endswith("on") # True
3. String Modification Methods
replace(old, new)
Replaces a substring.
"hello world".replace("world", "Python")
# "hello Python"
strip(), lstrip(), rstrip()
Removes whitespace or specified characters.
" hello ".strip() # "hello"
"@@hello@@".strip("@") # "hello"
4. Splitting & Joining Strings
split()
Splits string into list.
"a,b,c".split(",") # ['a','b','c']
rsplit()
Splits from right side.
splitlines()
Splits string by newlines.
join()
Joins list into string.
"-".join(["a","b","c"]) # "a-b-c"
5. Checking Character Types (Boolean Methods)
These return True or False.
isalnum() – Alphanumeric
isalpha() – Alphabetic
isdigit() – Digits only
isnumeric() – Numeric (includes unicode numbers)
isdecimal() – Decimal digits only
islower(), isupper()
istitle() – Title-case check
isspace() – Only spaces
Example:
"123".isdigit() # True
"hello".isalpha() # True
"Hello World".isspace() # False
6. Alignment Methods
Used for formatting output.
center(width, fillchar)
Centers text.
"hi".center(10, "*")
# "***hi****"
ljust(width) — left-justify
rjust(width) — right-justify
7. Encoding / Decoding Methods
encode()
Converts string to bytes.
"hello".encode()
# b'hello'
8. String Testing & Utilities
count()
Counts occurrence of substring.
"hello".count("l") # 2
format() and format_map()
String formatting.
"Name: {}".format("Alice")
maketrans() & translate()
Used for character mapping or replacement.