0% found this document useful (0 votes)
3 views5 pages

String in Python

In Python, a string is defined as a sequence of characters enclosed in single, double, or triple quotes, representing text data. Strings are immutable, meaning they cannot be changed after creation, and common operations include concatenation, repetition, and using various string functions. The document also provides examples of string creation, character indexing, and useful string methods.

Uploaded by

jaatnimor561
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)
3 views5 pages

String in Python

In Python, a string is defined as a sequence of characters enclosed in single, double, or triple quotes, representing text data. Strings are immutable, meaning they cannot be changed after creation, and common operations include concatenation, repetition, and using various string functions. The document also provides examples of string creation, character indexing, and useful string methods.

Uploaded by

jaatnimor561
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

5/13/26, 6:44 PM String in Python

string in python in simple words

String in Python (Simple Words)


In Python, a string means a sequence of characters (letters, numbers, symbols) written
inside quotes.

👉 Simple meaning:
A string is text or words stored in a variable.

Example

name = "Sarika"
city = 'Delhi'
Python Run

Here:
"Sarika" is a string
'Delhi' is also a string

Both are text values.

1. How to Create a String


In Python, strings are written inside:

1️⃣ Single quotes

a = 'Hello'
Python Run

2️⃣ Double quotes

b = "Hello"
Python Run
[Link] 1/5
5/13/26, 6:44 PM String in Python

3️⃣ Triple quotes (for long text)

c = """Hello
This is Python"""
Python Run

2. Example of String

text = "Python is easy"


print(text)
Python Run

Output:

Python is easy

Here Python is easy is a string.

3. Characters in String
A string is made of characters.

Example:

"HELLO"

Position Character

0 H

1 E

2 L

3 L

4 O
ChatGPT Get Plus

[Link] 2/5
5/13/26, 6:44 PM String in Python

Python starts counting from 0.

Example:

Python Run

word = "HELLO"
print(word[0])

Output:

4. String is Immutable
In Python, strings cannot be changed after creation.

Example:

Python Run

text = "Hello"
text[0] = "Y" # Error

Python will give an error because string values cannot be modified directly.

5. Common String Operations

1️⃣ Concatenation (Joining Strings)

Python Run

a = "Hello"
b = "World"
print(a + b)

Output:

HelloWorld

[Link] 3/5
5/13/26, 6:44 PM String in Python

2️⃣ Repetition

Python Run

print("Hi" * 3)

Output:

HiHiHi

3️⃣ Length of String

Python Run

text = "Python"
print(len(text))

Output:

6. Some Useful String Functions


Function Use

upper() Convert to capital letters

lower() Convert to small letters

replace() Replace word

split() Split string

len() Find length

Example:

[Link] 4/5
5/13/26, 6:44 PM String in Python

Python Run

text = "python"

print([Link]())
print([Link]())

Output:

PYTHON
python

✔ In one line definition (for exam):


String in Python is a sequence of characters enclosed in single, double, or triple quotes
used to represent text data.

If you want, I can also explain:


String methods in Python (20+ important ones)
String indexing and slicing (very important for exams)
Python string programs for UG exams.

[Link] 5/5

You might also like