Document 1
Document 1
Prince Saini
CSE (AL & ML)
3rd Year
# Checking conditions
if num > 0:
else:
# Checking conditions
if char.isalpha():
print("It is an alphabet.")
elif char.isdigit():
print("It is a digit.")
else:
# Checking conditions
if char.isupper():
elif char.islower():
else:
print("Invalid input!")
month_days = {
if month == 2:
else:
else:
file.write(content)
def read_file():
try:
except FileNotFoundError:
def insert_file():
file.write("\n" + content)
def delete_file():
import os
if os.path.exists("data.txt"):
os.remove("data.txt")
else:
while True:
if choice == 1:
write_file()
elif choice == 2:
read_file()
elif choice == 3:
insert_file()
elif choice == 4:
delete_file()
elif choice == 5:
break
else:
6. Encapsulation in Python
Encapsulation is the concept of wrapping data and methods in a class and restricting access
to some of them.
class BankAccount:
if amount > 0:
self.__balance += amount
else:
print("Invalid amount.")
self.__balance -= amount
else:
def get_balance(self):
account.deposit(500)
account.withdraw(300)
Removes Element at specified index (default last) First occurrence of specified value
split() Splits string based on pattern re.split(r'\s+', 'hello world') → ['hello', 'world']