Grade 7-ICT-Python - Asynchronous Learning
Grade 7-ICT-Python - Asynchronous Learning
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 ' ').
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
Write a program to input a sting of your choice and perform the following string
operations:
Page No:2
NPS International School
Page No:3