-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment2.2.py
More file actions
58 lines (55 loc) · 1.05 KB
/
Assignment2.2.py
File metadata and controls
58 lines (55 loc) · 1.05 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
55
56
57
58
#1)
x=(1,2,3)
x=list(x)
x[0]=5
x=tuple(x)
print(x)
#2)
""" String methods """
a="Hello"
print(a)
print(a[0])
for i in a:
print(i,end="")
print("\n")
print(len(a))
if "e" in a:
print("Yes e in a")
print(a[0:2])
print(a[-5:-2])
print(a.upper())
print(a.lower())
a=" Hello "
print(a.strip())
a="Hello"
print(a.replace("H","J"))
print(a.split())
print("a"+"n")
age="Name"
txt="my name is {}"
print(txt.format(age))
name="Name"
age=18
txt="My name is {} and age {}"
print(txt.format(name,age))
print(a.capitalize())
m="text"
s=""
print(s.join(m))
print(a.startswith("h"))
print(a.endswith("o"))
#3)
""" Dictionary Methods """
dict={1:"name", 2:"Age", 3:"Place", 4:"Profession"}
dict.clear()
print(dict)
dict={1:"name", 2:"Age", 3:"Place", 4:"Profession"}
print(dict.get(1))
dict={1:"name", 2:"Age", 3:"Place", 4:"Profession"}
print(dict.pop(1))
dict={1:"name", 2:"Age", 3:"Place", 4:"Profession"}
print(dict.setdefault(3))
print(dict.values())
# Create a dictionary with a number as the key and list, dictionary as a value
d1={1:[1,2,3]}
d2={2:{"one":"name","two":"age"}}