In [ ]:
some_tuple = (10,20,30)
print(some_tuple[1])
In [ ]:
some_tuple = (10,20,30)
print(some_tuple[:])
In [ ]:
some_tuple = (10,20,30)
some_tuple[1] = 50
In [ ]:
some_tuple = (10,20,30)
some_tuple.append(10)
Geeky note: tuples are useful because they are "hashable" and can be used as keys for dictionaries, while lists are not hashable and can't be dictionary keys.
In [ ]:
a_string = "This is a string"
print(a_string[0])
print(a_string[5:])
print(a_string[:-3])
In [ ]:
a_string = "This is a string"
a_string[0] = "a"
In [ ]:
a_string = "This is a string"
print(a_string)
#Convert the string to a list
a_list = list(a_string)
# Set the first element in the list to "a"
a_list[0] = "a"
# Convert the list back to a string
a_string = "".join(a_list)
print(a_string)
In [ ]:
some_dict = {"a":10,
"b":20,
"c":30}
print(some_dict["a"])
print(some_dict["b"])
In [ ]:
another_dict = {1:10,
"test":print,
1.5:-10,
(1,2,3):"cow"}
print(another_dict["test"])
print(another_dict[(1,2,3)])
In [ ]:
some_dict = {"a":10,
"b":20,
"c":30}
print(some_dict[10])
In [ ]:
some_dict = {"a":10,"b":20,"c":30}
for k in some_dict.keys():
print(k,some_dict[k])
In [ ]:
some_dict = {"a":10,"b":20,"c":30}
for v in some_dict.values():
print(v)
In [ ]:
some_dict = {"a":10,"b":20,"c":30}
some_dict["c"] = 50
print(some_dict)
In [ ]:
some_dict = {"a":10,"b":20,"c":30}
some_dict["d"] = 50
print(some_dict)
In [ ]:
some_dict = {"a":10,"b":20,"c":30}
x = some_dict.pop("a")
print(x)
print(some_dict)
In [ ]: