Lesson 4 - String Handling
Lesson 4 - String Handling
Class Starter: Recall is the ability to remember something that has happened
in the past or the act of remembering it.
Steps to success:
I can define the term string.
Learning I don’t I can explain I can compare I can outline and I can write at least
Objective: Be know what is meant and contrast explain the three lines of
able to anything by string between an different string codes using
understand the about string handling. upper string handling different string
different handling. and a lower features used in handling features.
string string. Python.
handling
features in
Python.
Keywords
String
String handling
String slicing
Complete Task in pairs British Value:
Individual Liberty: You
Fish and Hook/Pre-Learning Task. may choose the questions
you would like to answer.
Steps to Success Not sure One idea Multiple ideas Linking ideas Applying ideas
Learning I don’t I can I can I can outline and I can write at least
Objective: Be know explain compare and explain the three lines of codes
able to Compare and
anything what is contrast different string using different
contrast Write at least two
understand the about stringExplain
meant bywhat between
between Outlinefeatures
an handling and string handling
lines using two
Define the
different string is meant by string upper explain three
handling. string upper string used in Python. different string
features.
term string. string and string string handling
handling features
handling handling. and a lower features.
handling. lower in in Python.
features in string.
Python.
Python.
Cognition needed: Resourcefulness
Start at your most Resourcefulness the ability to find quick
challenging question. and clever ways to overcome difficulties
Culture Curriculum: Learning about the
Careers Section: different jobs available within the career
area of Computer Science.
Strings are always created as a response to the input function – e.g. “How do you feel?”
String features:
1. Changing the case of a string:
You can change the case of a string to either uppercase or lowercase
#Changing a string to upper case #Changing a string to lower case
Message = “wake up” Message = “SHHH, THIS IS A LIBRARY”
upperMessage = Message.upper() lowerMessage = Message.lower()
print(upperMessage) print(lowerMessage)
String handling
String features:
1. Counting the number of characters in a string.
You can use len() and .count() to count the characters in a string.
length = len(“billabong”) length = len (“Once upon a time”)
print (length) print (length)
Output will be 9 Output will be 16
fruit = (“pineapple”)
letterP = fruit.count(“p”)
print (letterP)
Output will be 3
String handling
String features:
1. Counting the number of characters in a string.
You can use len() and .count() to count the characters in a string.
length = len(“billabong”) length = len (“Once upon a time”)
print (length) print (length)
Output will be 9 Output will be 16
fruit = (“pineapple”)
letterP = fruit.count(“p”)
print (letterP)
Output will be 3
String handling
Positive indexing starts at the
String features: beginning of a string and
1. Index and positioning negative indexing starts at the
end.
Python automatically assigned a numerical value to each character’s position in a
string.
Look at the index table below for the string “White Rabbit”.
String W H I T E R A B B I T
Positive 0 1 2 3 4 5 6 7 8 9 10 11
Index
You can use indices to slice strings, giving you a substring or single character.
Learning I don’t know I can explain I can compare I can outline I can write at
Objective: Be anything about what is meant and contrast and explain the least three
Page 31 Page 31
able to string by string Page
between an 32 string lines
different Pageof 32
codes
Question 1-2
understand the Questionupper
1-4string
Question 5-6 Question 5-7
handling. handling. handling using different
different string and a lower features used string handling
handling string. in Python. features.
features in
Cognition needed: Resourcefulness
Python. Resourcefulness the ability to find quick
and clever ways to overcome difficulties
Practical Task: Complete the following in Python
Learning I don’t I can explain I can compare I can outline and I can write at least
Objective: Be know what is meant and contrast explain the three lines of
able to anything by string between an different string codes using
understand the about string handling. upper string handling different string
different handling. and a lower features used in handling features.
string string. Python.
handling
features in
Python.
Cognition needed: Recall
Recall is the ability to remember something that has happened
Plenary
in the past or the act of remembering it.