-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_string_dictionary.py
More file actions
64 lines (61 loc) · 1.55 KB
/
list_string_dictionary.py
File metadata and controls
64 lines (61 loc) · 1.55 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
59
60
61
62
63
64
# concept of string and list overlap
print(dir(list))
# u can always know about a attribute using help
help(list.append)
mylist = [1, 2, 3, 4, 5, 6]
print(mylist)
mylist.append(10)
print(mylist)
mylist.append("hey hey")
print(mylist)
# remove all items from the list
mylist.clear()
print(mylist)
mylist.append("ash")
mylist.append("mishty")
mylist.append(17)
print(mylist)
'''
The index() method returns the index of the specified element in the list.
The list index() method can take a maximum of three arguments:
element - the element to be searched
start (optional) - start searching from this index
end (optional) - search the element up to this index
he index() method returns the index of the given element in the list.
If the element is not found, a ValueError exception is raised.
Note: The index() method only returns the first occurrence of the matching element.
'''
# find the position
print(mylist.index("mishty"))
# print(mylist.index("mty"))
print(mylist[2])
print(mylist[1:2])
print(mylist[1:3])
print(mylist[:])
print(mylist[:3])
print(mylist[2:])
print(mylist[2:-1])
print(mylist[:-1])
# string
a = "abcdefghijk"
print(a.index('f'))
mylist.append(23)
mylist.append("abc")
mylist.append("abc")
mylist.append("abc")
print(mylist)
print(mylist.index("abc"))
print(mylist[4][1])
# select the item in 4th index,and then 1st index of that 4th index
# same things with dictionaries
student = {
"name": "ash",
"age": 17
}
print(student["name"]) # i wana know the name of student
# translation
lang = {
"water": "pani",
"morning": "subhah"
}
print(lang["water"])