Professional Documents
Culture Documents
Lesson 5
● What is String?
● Difference between String and numeric data
● String formatting methods
● Basic String operations
What is String?
String is a sequence of characters which includes:
Coding time!!
- letters (A-Z, a-z) Assign your name (in
string) to variable “name”
- numbers (0-9)
- other special characters (@#!$&?)
enclosed by single-quotes (‘ ‘) or double-quotes (“ “). Example of Strings
“Jonathan”
Which of your personal
informations are in String “Python is the best”
data types?
“2022 this year“
”pyth0n@#!$&_pa$$word”
Numeric Data VS. String Data
Operations Numeric (int or float) String
15 + 16 31 “1516”
“15” + “16”
15 * 3 45 “151515”
“15” * 3
Interpret as
Students need to String Concatenation
differentiate which data
types to use
Basic Mathematical Operation
(Add (+), Multiply (*))
String Formatting
In Python, we have different methods to format the output for display
purpose as below:
Python Syntax
Example Output
String Formatting - Multi-line Strings
Using multi-line strings, enclosed with triple single-quote (‘’’ ‘’’)
Python Syntax
Example Output
String Formatting - Placeholder
Using placeholder, int (%d), float (%f), string (%s)
Python Syntax
Example Output
String Operations
String data type in Python comes with many built-in functions as table below:
String Operations - How to apply?
Coding time!
Type the code out in editor
and fill in the blanks
??
??
?? ??
Display result
Question 1:
Index = 0
Index = 6
??
Use the first char +
mid char + last char
using index
Question 2: