-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_list.py
73 lines (69 loc) · 2.33 KB
/
10_list.py
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
65
66
67
68
69
70
71
72
73
#list ----[]----paranthesis
#list are used to store multiple iteems or attribute in single variable or entitiy
#list it can be changeable (MUTABLE)
#store multiple datatype
#nested - list
#different data-type in same list
##<List is a collection which is ordered and changeable. Allows duplicate members>
#can accept duplicate values and of any data type
tuple0 = [8,22,8,"safwan"]
print(type(tuple0))
example = ["sunady","monday","tuesday"]
print(example)
print("-------------------------------")
dif_data_type =[1,2.9,"safwan",True]
print(dif_data_type)
print(type(dif_data_type))
print(len(dif_data_type))
print("-------------------------------")
nested_list= ["python", [1,2,3], "safwan"]
print(nested_list)
print(type(nested_list))
print(len(nested_list))
print(nested_list[0]) #by indexing
print(nested_list[:3])#by slicing
print(nested_list[0]=="python")
nested_list[0]="java"
print(nested_list)
print(nested_list[0]=="python")
print(dif_data_type[0:3:1]) # 1 is the space b/w 0:3
dif_data_type.append(5) #in last
print(dif_data_type.append)
print("------Python - Change List Items------")
thislist = ["apple", "banana", "cherry"]
thislist[1] = "blackcurrant"
thislist.insert(0, "watermelon")
print(thislist)
print("------Python - Add List ------")
thislist = ["apple", "banana", "cherry"]
thislist.append("orange") ##--------------Append Items
print(thislist)
#--The insert() method inserts an item at the specified index:
print("----Insert Items----")
thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange") ##-----------Insert Items
print(thislist)
#To append elements from another list to the current list, use the extend() method.
print("-----Extend List-----")
thislist = ["apple", "banana", "cherry"]
tropical = ["mango", "pineapple", "papaya"]
thislist.extend(tropical) ##-----------Extend list
print(thislist)
print("---------REMOVE-------")
thislist = ["apple", "banana", "cherry", "banana", "kiwi"]
thislist.remove("banana")
print(thislist)
thislist = ["apple", "banana", "cherry"]
thislist.pop(1) ##Remove Specified Index
print(thislist)
thislist = ["apple", "banana", "cherry"]
del thislist[0] ##delete the list
print(thislist)
print("-------------------------------")
#add string to list
name = "safwan" #string
print(list(name)) #list
line=["a",1,"b",2]#list
print(list(name)+line) # concatinating two list
str = "Hello"
print(id(str))