0% found this document useful (0 votes)
6 views2 pages

Python String Basics and Methods

This document provides a comprehensive overview of strings in Python, defining them as immutable sequences of characters. It covers various ways to create strings, their properties, operations that can be performed on them, and a variety of built-in string methods for manipulation and formatting. Examples are included to illustrate the use of these methods.

Uploaded by

mmgsg103
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)
6 views2 pages

Python String Basics and Methods

This document provides a comprehensive overview of strings in Python, defining them as immutable sequences of characters. It covers various ways to create strings, their properties, operations that can be performed on them, and a variety of built-in string methods for manipulation and formatting. Examples are included to illustrate the use of these methods.

Uploaded by

mmgsg103
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

STRING – COMPLETE PYTHON NOTES

1. What is a String?

A string is a sequence of characters enclosed in quotes. Immutable and ordered.

2. Creating Strings (5 Ways)

1. s = 'Hello'

2. s = "Hello World"

3. s = '''multi

line'''

4. s = str(123)

5. s = ""

3. Properties of Strings

1. Ordered

2. Immutable

3. Iterable

4. Indexing allowed

5. Slicing possible

6. Supports special characters

7. Rich built■in methods

4. Operations on Strings

1. Concatenation: "hello" + "world"

2. Repetition: "ha"*3

3. Slicing: s[1:4]

4. Membership: 'a' in s

5. Comparison: "abc" < "xyz"

6. Length: len(s)

7. Iteration: for c in s

5. String Methods

A) Case Conversion
upper(), lower(), title(), capitalize(), swapcase()

B) Search & Replace

find(), rfind(), index(), count(), replace()

C) Validation

isalnum(), isalpha(), isdigit(), isspace(), islower(), isupper()

D) Alignment

center(), ljust(), rjust()

E) Splitting & Joining

split(), rsplit(), splitlines(), join()

F) Formatting

format(), f-strings, % formatting

Example Block:

s = "rakshita"

print([Link]())

print([Link]("a"))

print("-".join(["A", "B", "C"]))

You might also like