import math
# sample numbers
a = -5
b = -3.7
print("abs(a):", abs(a)) # absolute value (built-in)
print("[Link](b):", [Link](b)) # smallest integer ≥ b
print("[Link](1):", [Link](1)) # e^1
print("[Link](b):", [Link](b)) # absolute value (float)
OUTPUT
abs(a): 5
[Link](b): -3
[Link](1): 2.718281828459045
[Link](b): 3.7
s = " Hello "
2)STRING
print(len(s)) # len()
print([Link]()) # upper()
print([Link]()) # lower()
print([Link]()) # strip()
print([Link]("He", "Me")) # replace()
print(s[2:5]) # slicing
print(s[::-1]) # reverse slicing
for ch in s: # iteration
print(ch, end=" ")
try:
s[0] = 'h' # immutability
except TypeError:
print("\nString is immutable")
OUTPUT:
HELLO
hello
Hello
Mello
He
olleH
Hello
String is immutable
3)LIST
lst = [10, 20, 30, 40, 50]
print(len(lst)) # length of list
print(max(lst)) # largest value
print(min(lst)) # smallest value
[Link](60) # add an item
[Link](30) # remove an item
print(lst)
print(lst[1:4]) # slicing
for item in lst: # iteration
print(item, end=" ")
lst[0] = 100 # lists are mutable
print("\nList is mutable, modified:", lst)
OUTPUT:
50
10
[10, 20, 40, 50, 60]
[20, 40, 50]
10 20 40 50 60
List is mutable, modified: [100, 20, 40, 50, 60]
4)TUPLES
t = (10, 20, 30, 40, 50, 20)
print(len(t)) # length
print(max(t)) # largest
print(min(t)) # smallest
print([Link](20)) # count occurrences
print([Link](40)) # index of value
print(t[1:4]) # slicing
for item in t: # iteration
print(item, end=" ")
try:
t[0] = 100 # tuples are immutable
except TypeError:
print("\nTuple is immutable")
OUTPUT
50
10
(20, 30, 40)
10 20 30 40 50 20
Tuple is immutable