Skip to content

Commit 1eff15d

Browse files
committed
addded code for dictionary , tuples and did the exercise 1 on strings in python
1 parent cdc886a commit 1eff15d

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

String in Python/exercise1.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
street="Walawwatta place"
2+
city="Colombo"
3+
country="Sri Lanka"
4+
5+
address=street+" "+city+" "+country
6+
print(address)
7+
8+
print(f"Street is {street} and city is {city} and country is {country}")

String in Python/exercise2.py

Whitespace-only changes.

String in Python/exercise3.py

Whitespace-only changes.

String in Python/exercise4.py

Whitespace-only changes.

dictioanry.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
d={"Tom":734342343,"rob":21325245,"joe":3424234324}
2+
d
3+
{'Tom': 734342343, 'rob': 21325245, 'joe': 3424234324}
4+
d["Tom"]
5+
734342343
6+
7+
# Changin the value in a dictionary
8+
9+
d["sam"]=21321432523
10+
d
11+
{'Tom': 734342343, 'rob': 21325245, 'joe': 3424234324, 'sam': 21321432523}
12+
d["rob"]=132123123
13+
d
14+
{'Tom': 734342343, 'rob': 132123123, 'joe': 3424234324, 'sam': 21321432523}
15+
del d["sam"]
16+
d
17+
{'Tom': 734342343, 'rob': 132123123, 'joe': 3424234324}
18+
19+
# displaying the dictionary values
20+
21+
# 1. One way
22+
23+
for key in d:
24+
print("Key is: ",key," value is ",d[key])
25+
26+
# 2. Two way
27+
28+
for key , value in d.items():
29+
print("Key is ",key, " Value is ",value)
30+
31+
32+
# Search for a value in dictionary
33+
34+
"tom" in d
35+
False
36+
"Tom" in d
37+
True
38+
39+
# Wipe out the data in a dictionary
40+
41+
d.clear()

tuple.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
point=(5,9)
2+
point[0]
3+
5
4+
point[1]
5+
9
6+
point[0:]
7+
(5, 9)
8+
# list: all the values have similar meaning (Homogeneous)
9+
#tuple: all values have different meaning (heterogeneous)
10+
11+
#example address=("100101","New york")
12+
#tuples are immumatable
13+
14+
point[1]=0 #this will give me an error

0 commit comments

Comments
 (0)