Strings In Python - Python Notes By Mr. BILRED | TechAmbitionX

Strings in Python — Say Hello to Text | TechAmbitionX

Strings in Python — Say Hello to Text

A string in Python is just a bunch of characters inside quotes.

Single quotes or double quotes — both work:

name = "Bilal"
greeting = 'Hello World'
empty = ""

They can contain numbers, symbols, even emojis:

info = "Python 3.11 rocks! 🤘"

How to Use Strings in Python

1. Concatenation (Joining Strings)

first = "Mr. "
last = "BILRED"
full = first + last
print(full)  # Mr. BILRED

2. String Length

name = "Bilal"
print(len(name))  # 5

3. Accessing Characters

name = "Bilal"
print(name[0])   # B
print(name[-1])  # l

4. Slicing Strings (obv that means k "kaatna")

print(name[0:3])  # Bil
print(name[:4])   # Bila
print(name[2:])   # lal

5. String Methods

msg = "python is awesome"

print(msg.upper())      # PYTHON IS AWESOME
print(msg.capitalize()) # Python is awesome
print(msg.replace("awesome", "fun"))  # python is fun
print("tech" in msg)    # False

6. Multiline Strings

story = """This is a 
multi-line 
string."""
print(story)

7. formatted Strings (Python 3.6+)

name = "Bilal"
age = 20
print(f"My name is {name} and I am {age} years old.")

REMEMBER: Anything inside quotes is a string — even numbers like "1234" are strings.

That’s it for strings. For now...

SSBkb24ndCBrbm93IGhvdyBsb25nIEknbGwgbGl2ZSwgYnV0IG1hbiwgSSB3YW5uYSBtYWtlIHRoZSBtb3N0IG9mIG15IExpZmUuLi4=

I just wanted to say that...

By the way, if you wanna learn python, visit sites like w3schools! they can be helpful...

Try Your Code

Comments

Popular posts from this blog

C++ escape sequences with clear examples and outputs - Compiled By Bilal Ahmad Khan AKA Mr. BILRED

Bits, Bytes, Binary, and ASCII: The Fundamentals of Data Representation - Compiled By Bilal Ahmad Khan AKA Mr. BILRED - TechAmbitionX

Bipolar Junction Transistor | TechAmbitionX | Notes By BILRED