You are on page 1of 3

NPS International School

Topic: Python Programming

Name: _______ Subject: ICT

Date: ________ Grade: 7

String Functions:

A string is a list of characters in order. A character is anything you can type on the
keyboard in one keystroke, like a letter, a number, or a backslash. Strings can have
spaces: "hello world". An empty string is a string that has 0 characters. Python
recognize as strings everything that is delimited by quotation marks (" " or ' ').

Creation word = "Hello World"


print( word)
Output
Hello World
Accessing : Use [ ] to access word = "Hello World"
characters in a string letter=word[0]
print(letter)

H
Length word = "Hello World"
print(len(word))
Output
11
Finding word = "Hello World"
print (word.count('l'))
# count how many times l is in the
string
Output
3
Split Strings word = "Hello World"
print(word.split(' '))
# Split on whitespace
Output
['Hello', 'World']
Changing Upper and Lower Case String1 = "Hello World"
Strings print( string1.upper())
Output
HELLO WORLD

Page No:1
NPS International School

print(string1.lower())
Output
hello world

print(string1.title())
Output
Hello World

print(string1.capitalize())
Hello world

print(string1.swapcase())
Output
hELLO wORLD

print(string1.replace(“World”,”Python
”)
Output
Hello Python

Task 7: String Manipulation [5 Marks]

Write a program to input a sting of your choice and perform the following string
operations:

a. Change to lowercase letters


b. Capitalize the first character of each word
c. Calculate the length of the string
d. Access the character in 4th place of your string.
e. Count how many times the character ‘a’ is appearing in your string.

Page No:2
NPS International School

------End of Task 7 ----------

Page No:3

You might also like