0% found this document useful (0 votes)
5 views1 page

Python Strings Notes

Python strings are immutable sequences of characters used for text manipulation, which can be defined using single, double, or triple quotes. Key string functions include upper(), lower(), capitalize(), and many others that perform various operations such as converting cases, stripping spaces, and counting occurrences. Understanding these functions enhances the ability to effectively work with strings in Python.

Uploaded by

omarsulaiman359
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Python Strings Notes

Python strings are immutable sequences of characters used for text manipulation, which can be defined using single, double, or triple quotes. Key string functions include upper(), lower(), capitalize(), and many others that perform various operations such as converting cases, stripping spaces, and counting occurrences. Understanding these functions enhances the ability to effectively work with strings in Python.

Uploaded by

omarsulaiman359
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Strings and Built-in Functions – Detailed

Notes

Python strings are sequences of characters used to store and manipulate text. Strings are
immutable, meaning they cannot be changed after they are created.

Strings can be written using single quotes ('text'), double quotes ("text"), or triple quotes for multiline
text.

Important properties of strings include indexing, slicing, and immutability.

Function Purpose Example


upper() Convert string to uppercase 'python'.upper() → PYTHON
lower() Convert string to lowercase 'HELLO'.lower() → hello
capitalize() Capitalize first letter 'python'.capitalize() → Python
title() Capitalize each word 'python language'.title()
strip() Remove spaces from ends ' hello '.strip()
replace() Replace part of string 'I like Java'.replace('Java','Python')
split() Split string into list 'Python is easy'.split()
join() Join list elements into string ' '.join(['Python','is','fun'])
find() Find index of substring 'python'.find('p')
count() Count occurrences 'banana'.count('a')
startswith() Check starting text 'Python'.startswith('Py')
endswith() Check ending text '[Link]'.endswith('.pdf')
isalpha() Check if letters only 'Python'.isalpha()
isdigit() Check if digits only '12345'.isdigit()
isalnum() Check letters or digits 'Python123'.isalnum()
len() Length of string len('Python')

You might also like