0% found this document useful (0 votes)
10 views

Lesson 4 - String Handling

Uploaded by

desav05582
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lesson 4 - String Handling

Uploaded by

desav05582
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Cognition needed: Recall

Class Starter: Recall is the ability to remember something that has happened
in the past or the act of remembering it.

1. What is a string? British Value: Individual


Liberty: You may choose the
questions you would like to
answer.
2. Name and explain two rational operators.

3. Explain what is meant by string handling.

4. Differentiate between MOD and DIV

5. Evaluate the value for each of the following:


String handling
Programming techniques British
Value:
Mutual
respect- we
treat others
the way we
would like to
be treated
LO: Be able to understand the different string handling features in
Python.

Steps to success:
I can define the term string.

I can differentiate between an upper string and a lower string.

I can outline and explain the different string handling features.

I can write code using at least three different string handling


features.
Start of Lesson (SOL)
Steps to Success Not sure One idea Multiple ideas Linking ideas Applying ideas

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.

1.Name three string instrument.


2.Outline and explain the effects of using technology when
playing different string instruments.
3.Evaluate the benefits of technology in the music industry and
how it contributes to innovation of new music.

Cognition needed: Resourcefulness


Resourcefulness the ability to find quick
and clever ways to overcome difficulties
String handling

Unlike numbers, strings are more difficult to process.

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

Negative -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1


Index
String handling
String features:
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
Negative -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
Index

You can use indices to slice strings, giving you a substring or single character.

#1 (one letter) #2 (first three letters) #3 (10th letter onward)


string = “white rabbit” string = “white rabbit” string = “white rabbit”
print (string[-5]) print (string[0: 3]) print (string[9:])
Output will be a Output will be whi Output will be bit
Cognition needed: Resilience:

Class Activity believing in ourselves and viewing


challenges as opportunities for better
learning.

Steps to Not sure​ One idea​ Multiple Linking ideas​ Applying


success​ ideas​ ideas​

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

1. In the script mode in Python, create a variable called weather.


2. In the variable created, write the string “today is very cold.”
3. Write a code that will print the string in uppercase.
4. Write a code that will count the amount of “o” in the string.
5. Write a code to print the length of the string.
6. Write a code to print the string into lowercase.
7. Write a string to print the 5 character of the string onwards.
Cognition needed: Resilience:
believing in ourselves and viewing
challenges as opportunities for better
learning.
End of Lesson (EOL)
Steps to Success Not sure One idea Multiple ideas Linking ideas Applying ideas

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.

1. Name two string handling features.

2. Explain what is meant by casting.

3. Differentiate between the data types and arithmetic


operators.
Skill needed:
Reflectiveness:
thinking about what
we are good at and
what we need to do to
improve to become
better learners

You might also like