
Python Strings and Character Encoding
Presentation
•
Computers
•
10th Grade
•
Practice Problem
•
Easy
Larbi Yazid
Used 7+ times
FREE Resource
18 Slides • 5 Questions
1
Python Strings and
Character Encoding
CSC501-Term 3
AQB ATHS 2022-2023
2
We'll be covering the following objectives:
PC2.1
Understand how characters are coded and stored in the computer's memory and recognize the main
encoding terms such as ASCII, Unicode, and codepoint.
PC2.2
Understand Strings as immutable sequence and write code to perform simple operations as concatenate +,
replicate *, ord(), chr(), indexing, slice, in , not in…etc
PC2.3
Differentiate between Strings and List in Python as immutable and mutable sequence.
PC2.4
Create simple program to use the main Python built-in functions such as min(), max(), list(), index(), count(),
PC2.5
Practice the standard Python strings’ methods capitalize(), center(), endswith(), find(), isalnum(),
isalpha()…etc
PC2.6
Write codes to sort String using sorted() & sort() functions , and compare Strings using logical operators.
PC2.7
Create programs that have the structure of accepting the user’s string input, process , then providing
expected output
3
Understanding Character Encoding
• In computers, characters are represented using bits.
• For example, the letter 'A' is represented as 01000001 in binary.
• There are several encoding schemes used to represent characters,
such as ASCII, Unicode, and codepoint.
• ASCII is a standard encoding scheme that represents characters using
7 bits.
4
Fill in the Blanks
5
Drag and Drop
6
Understanding
Character
Encoding
• ASCII stands for "American Standard Code
for Information Interchange".
• Unicode is a more advanced encoding
scheme that supports characters from
different languages and scripts and uses up
to 32 bits to represent a character.
• Codepoint is a unique identifier for each
character in Unicode.
• Understanding character encoding is
important for working with text data in
Python.
7
ASCII Sample
ASCII Vs Unicode
8
Drag and Drop
9
Drag and Drop
10
Working with Strings
• A string is a sequence of characters enclosed in quotes.
• Strings are immutable in Python, which means they
cannot be changed directly.
• You can perform several operations on strings, such as
concatenation (+), replication (*), ord() (to get the ASCII
value of a character), chr() (to get the character for an
ASCII value), indexing (to access individual characters in
a string), slicing (to extract a substring from a string), in
(to check if a substring is present in a string), and not in
(to check if a substring is not present in a string).
• Knowing how to work with strings is essential for
processing text data in Python.
11
Match
Match the following
String is
Strings are
concatenation (+), replication (*), ord()), chr(),slicing()
chr()
indexing
a sequence of characters enclosed in quotes
immutable in Python
are operations on strings
to get the character for an ASCII value
to access individual characters in a string
a sequence of characters enclosed in quotes
immutable in Python
are operations on strings
to get the character for an ASCII value
to access individual characters in a string
12
Samples:
13
Difference between Strings and Lists
• A list is a collection of items that can be of different types.
• Lists are mutable in Python, which means they can be changed
directly.
• The main difference between strings and lists is their mutability.
• You can perform several operations on lists, such as adding and
removing items, accessing individual items, and sorting the list.
• Understanding the difference between strings and lists is important
for choosing the appropriate data structure for your program.
14
Activity showing the difference
between String and list
• This code demonstrates the difference
between strings and lists in Python.
• The first section shows that strings are
immutable.
• The second section shows that lists are
mutable.
• The third section shows that strings
have some methods that lists don't
have, such as the split() method, which
splits a string into a list of substrings.
• The fourth section shows that lists have
some methods that strings don't have,
such as the append() method, which
adds an element to the end of a list.
15
Using Built-in Python Functions
• Python provides several built-in functions that you can use to process
strings and lists.
• Some of the main functions for lists include min(), max(), list(),
index(), and count().
• These functions can be used to perform common operations on lists,
such as finding the minimum and maximum values, converting a
string to a list, finding the index of an item, and counting the number
of occurrences of an item.
• You can use these functions in your programs to save time and effort.
16
• This code demonstrates how
to use the main built-in
functions in Python for lists.
• The first section shows how to
use the min() and max()
functions to find the minimum
and maximum values in a list.
• The second section shows
how to use the list() function
to convert a string to a list.
• The third section shows how
to use the index() function to
find the index of an item in a
list.
• The fourth section shows how
to use the count() function to
count the number of
occurrences of an item in a
list.
17
Practice Python String Methods
• Python provides several built-in methods that you can use to process
strings.
• Some of the main string methods include capitalize(), center(),
endswith(), find(), isalnum(), isalpha(), and many more.
• These methods can be used to perform common operations on
strings, such as capitalizing the first letter, centering the string,
checking if the string ends with a certain substring, checking if the
string is alphanumeric or alphabetic, and many more.
• You can use these methods in your programs to manipulate strings
easily and efficiently.
18
Examples:
19
Sorting Strings and Comparing Strings
• Python provides two functions for sorting
strings: sorted() and sort().
• sorted() returns a new sorted list of
characters from the original string, while
sort() sorts the original string in-place.
• You can also use logical operators to
compare strings, such as ==, !=, <, <=, >, and
>=.
• Understanding how to sort and compare
strings is important for processing text data
and performing string operations in Python.
20
Examples:
21
Accepting User Input and
Providing Output
• Python provides several built-in functions
for accepting user input and providing
output.
• The input() function can be used to accept
user input as a string, which can then be
processed in your program.
• The print() function can be used to provide
output to the user, such as the results of
string operations or program output.
• You can create programs that accept user
input, process it, and provide the expected
output using these functions.
22
Example:
23
Conclusion
• In this lesson, we covered several objectives related to working with strings
and character encoding in Python.
• We learned about character encoding schemes such as ASCII, Unicode, and
codepoint, and how to work with strings as immutable sequences using
various operations and methods.
• We also learned about the difference between strings and lists, and how to
use built-in Python functions to process them.
• Finally, we learned how to accept user input and provide output using
input() and print() functions.
• With these skills, you can start creating Python programs that work with
text data and manipulate strings efficiently and effectively.
Python Strings and
Character Encoding
CSC501-Term 3
AQB ATHS 2022-2023
Show answer
Auto Play
Slide 1 / 23
SLIDE
Similar Resources on Wayground
16 questions
Sex-linked traits
Presentation
•
10th Grade
20 questions
Poetic Devices
Presentation
•
10th Grade
19 questions
Parts of the motherboard
Presentation
•
10th Grade
18 questions
Improving Paragraphs
Presentation
•
10th Grade
19 questions
The study of cells using the Microscope
Presentation
•
10th Grade
19 questions
Electron Configuration- Practice
Presentation
•
10th Grade
17 questions
Alcohol
Presentation
•
10th Grade
17 questions
Imperialism in India
Presentation
•
10th Grade
Popular Resources on Wayground
19 questions
Naming Polygons
Quiz
•
3rd Grade
10 questions
Prime Factorization
Quiz
•
6th Grade
20 questions
Math Review
Quiz
•
3rd Grade
15 questions
Fast food
Quiz
•
7th Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade