-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit-2
More file actions
54 lines (44 loc) · 1.25 KB
/
Unit-2
File metadata and controls
54 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
7) #Function that returns multiple values
def calculate_operations(a, b):
return a + b, a - b, a * b
num1, num2 = 10, 5
results = calculate_operations(num1, num2)
print("Sum:", results[0])
print("Difference:", results[1])
print("Product:", results[2])
8) #Function with default arguments
def power(base=2, exponent=3):
return base ** exponent
print("Default power (2^3):", power())
print("Power with base 4 (4^3):", power(4))
print("Power with base 5 and exponent 2 (5^2):", power(5, 2))
9) #length of a string
def string_length(input_string):
count = 0
for char in input_string:
count += 1
return count
string = "Ravali"
length = string_length(string)
print(f"The length of the string is: {length}")
10) #substring is present in string or not
def subStr(s, sub):
return sub in s
print(subStr('RavaliKoppisetti', 'Ravali'))
11) #addition,insertion,slicing
lst = [1, 2, 3, 4, 5]
lst.append(6)
print("After addition:", lst)
lst.insert(2, 9)
print("After insertion:", lst)
print("After slicing:", lst[1:4])
12) #5built in functions
lst = [1, 2, 3, 4, 5, 6, 3, 9]
print("Count:", lst.count(9))
print("Index:", lst.index(3))
lst.sort()
print("Sort:", lst)
lst.reverse()
print("Reverse:", lst)
lst.extend([7, 8, 9])
print("Extend:", lst)