Lecture 7 - Python
Lecture 7 - Python
Sherina Sally
• Immutable
All Rights Reserved
• Each character of the string can be accessed using the position of the element
- Positioning starts from 0
- Python supports negative indexing
- Python doesn’t have a separate data type to represent characters
1
PYTHON STRINGS …(2)
• Obtain the length of a String by len()
STRING SLICING
• Extracts a part from a string as a substring
str[a : b]
All Rights Reserved
2
STRING OPERATORS
• Combines two strings by the “+” operator
str1 + str2
str1 * 3
format() …(1)
• Combines numerals to strings through placeholders
3
format() …(2)
STRING FUNCTIONS
4
Department of ICT, Faculty of Technology, University of Colombo