0% found this document useful (0 votes)
2 views3 pages

Python Strings Notes

The document provides comprehensive notes on Python strings, covering their definition, indexing, slicing, operations, methods, and formatting. It also discusses string immutability, comparison, iteration, testing methods, and encoding/decoding. Additional topics include string joining, partitioning, alignment, and specialized methods like casefold and zfill.

Uploaded by

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

Python Strings Notes

The document provides comprehensive notes on Python strings, covering their definition, indexing, slicing, operations, methods, and formatting. It also discusses string immutability, comparison, iteration, testing methods, and encoding/decoding. Additional topics include string joining, partitioning, alignment, and specialized methods like casefold and zfill.

Uploaded by

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

Python Strings – Topic-Wise Notes

1. Introduction to Strings
 Strings are sequences of characters enclosed in single ('...') or double ("...") quotes.
 Triple quotes ('''...''' or """...""") are used for multi-line strings.

2. String Indexing and Slicing


 Indexing allows accessing individual characters using positive or negative indices.
 Slicing extracts parts of strings using syntax s[start:end:step].

3. String Operations
 Concatenation: use '+' to combine strings.
 Repetition: use '*' to repeat strings.
 Membership testing: use 'in' or 'not in'.

4. String Methods
 Case conversion: upper(), lower(), capitalize().
 Searching: find(), replace().
 Splitting/Joining: split(), join().
 Trimming: strip(), lstrip(), rstrip().

5. String Formatting
 Use format() for traditional formatting.
 Use f-strings (f'...') for concise formatting.

6. Escape Characters
 \n for newline, \t for tab, \' for single quote, \\ for backslash.

7. String Comparison
 Use comparison operators (==, !=, <, >) to compare strings lexicographically.

8. String Immutability
 Strings cannot be changed after creation. Use slicing to create modified copies.
9. String Methods Overview
 len(), isalpha(), isdigit(), startswith(), endswith() are common methods.

10. String Iteration


 Iterate over characters in a string using a for-loop.

11. String Testing Methods


 isalnum(), isalpha(), isdigit(), islower(), isupper() test string content.

12. String Identity and Interning


 Python reuses string objects with the same value for efficiency.

13. String Encoding and Decoding


 Use encode() to convert to bytes, decode() to convert back to string.

14. String Joining and Splitting


 join() combines list elements into a string, split() breaks a string into a list.

15. String Formatting with Dictionaries


 Use format(**dict) to plug in dictionary values into strings.

16. String Translation and Mapping


 Use [Link]() with translate() to replace multiple characters.

17. String Partitioning


 partition() splits string into a 3-tuple at the first occurrence of a separator.

18. String Centering and Alignment


 Use center(), ljust(), rjust() to align strings within a given width.

19. String Casefolding


 casefold() provides aggressive lowercasing for caseless matching.
20. String Zfill
 zfill(width) pads string on the left with zeros to fill the width.

You might also like