Python Basics - B.Tech CSE Notes (Part
2)
5. Strings in Python
Strings are sequences of Unicode characters. They are immutable, which means they cannot
be changed after creation.
Examples:
name = "Jainee"
print(name.upper()) # Output: JAINEE
print(name.lower()) # Output: jainee
print(name[0]) # Output: J
String Methods:
- upper(), lower()
- strip(), replace(), split()
- find(), index(), count()
6. List Operations
Lists are ordered, mutable collections. They can hold different data types.
Example:
fruits = ["apple", "banana", "cherry"]
fruits.append("mango")
fruits.remove("banana")
print(fruits) # Output: ['apple', 'cherry', 'mango']
Useful Methods:
- append(), insert(), remove(), pop()
- sort(), reverse()
- len(), index(), count()
7. Dictionary Operations
Dictionaries are key-value pairs and are unordered.
Example:
student = {"name": "Jainee", "age": 18, "course": "CSE"}
print(student["name"]) # Output: Jainee
2)
5. Strings in Python
Strings are sequences of Unicode characters. They are immutable, which means they cannot
be changed after creation.
Examples:
name = "Jainee"
print(name.upper()) # Output: JAINEE
print(name.lower()) # Output: jainee
print(name[0]) # Output: J
String Methods:
- upper(), lower()
- strip(), replace(), split()
- find(), index(), count()
6. List Operations
Lists are ordered, mutable collections. They can hold different data types.
Example:
fruits = ["apple", "banana", "cherry"]
fruits.append("mango")
fruits.remove("banana")
print(fruits) # Output: ['apple', 'cherry', 'mango']
Useful Methods:
- append(), insert(), remove(), pop()
- sort(), reverse()
- len(), index(), count()
7. Dictionary Operations
Dictionaries are key-value pairs and are unordered.
Example:
student = {"name": "Jainee", "age": 18, "course": "CSE"}
print(student["name"]) # Output: Jainee