the following is the missed list in the python
shop_list = ["milk powder","baba chivda","bread",56,"tata namak"]
print(shop_list)
accessing the any element in the list using the index in the python
print(shop_list[3])
Now You can slice the list ... The following slicing is the skip the 1 element of the list in the python
print(shop_list[::2])
ouput:-['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
Now You can slice the list ... The following slicing is the skip the 1 element of the list .... in the negative index
print(shop_list[::-2])
output:- ['milk powder', 'baba chivda', 'bread', 56, 'tata namak'] if you want to add the some value in the lists now you can easily append in the lists.. the append function add the value in the last of the lists
shop_list.append("Test")
print(shop_list)
output:- ['milk powder', 'baba chivda', 'bread', 56, 'tata namak']# if you want to add the some value in the particular index then please use the insert function in the python... 1 is the index and Insert_function is the value which you can appent
shop_list.insert(1,"Insert_function")
print(shop_list)
# if the any value which you want to the remove ... then you can use the remove function ...and put the value which you want to the remove
shop_list.remove("Insert_function")
print(shop_list)
# if the value which you delete the last in the list then you can use the pop function
shop_list.pop()
print(shop_list)
# list is mutable in the python means you can change the any value in the list
shop_list[1] = "test"
print(shop_list)
# list is sort function you can use
shop_list1 = [1,45,34,23,78,90]
shop_list1.sort()
print(shop_list1)
shop_list1.extend("2")
print(shop_list1)
print(shop_list1)
#Now we can learn aand execute the tuple ,,,, the following is the tuple syntax
tp = (1,2)
print(tp)
# Sweap the two number in the python
a=1
b=17
a,b=b,a
print(a,b)
output command wise :- PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
56
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
File "c:\python code\Listsandtuplefunction.py", line 11
print(::1)
SyntaxError: invalid syntax
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
File "c:\python code\Listsandtuplefunction.py", line 11
^
SyntaxError: invalid syntax
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
56
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
['milk powder', 'bread', 'tata namak']
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['tata namak', 56, 'bread', 'baba chivda', 'milk powder']
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
Traceback (most recent call last):
File "c:\python code\Listsandtuplefunction.py", line 26, in <module>
shop_list.remove(1)
ValueError: list.remove(x): x not in list
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
Traceback (most recent call last):
File "c:\python code\Listsandtuplefunction.py", line 30, in <module>
shop_list.pop("pop_function")
TypeError: 'str' object cannot be interpreted as an integer
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
['milk powder', 'test', 'bread', 56, 'tata namak']
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
['milk powder', 'test', 'bread', 56, 'tata namak']
(1, 2)
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
['milk powder', 'test', 'bread', 56, 'tata namak']
(1, 2)
17 1
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
['milk powder', 'test', 'bread', 56, 'tata namak']
Traceback (most recent call last):
File "c:\python code\Listsandtuplefunction.py", line 38, in <module>
shop_list.sort()
TypeError: '<' not supported between instances of 'int' and 'str'
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
['milk powder', 'test', 'bread', 56, 'tata namak']
[1, 23, 34, 45, 78, 90]
(1, 2)
17 1
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
[1, 23, 34, 45, 78, 90]
Traceback (most recent call last):
File "c:\python code\Listsandtuplefunction.py", line 42, in <module>
print(shop_list1.max())
^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'max'
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
[1, 23, 34, 45, 78, 90]
Traceback (most recent call last):
File "c:\python code\Listsandtuplefunction.py", line 42, in <module>
print(shop_list1())
^^^^^^^^^^^^
TypeError: 'list' object is not callable
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'test', 'bread', 56, 'tata namak']
[1, 23, 34, 45, 78, 90]
[1, 23, 34, 45, 78, 90, '2']
[1, 23, 34, 45, 78, 90, '2']
(1, 2)
17 1
PS C:\python code> & "C:/python 3.11/python.exe" "c:/python code/Listsandtuplefunction.py"
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
56
['milk powder', 'bread', 'tata namak']
['tata namak', 'bread', 'milk powder']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'Insert_function', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak', 'Test']
['milk powder', 'baba chivda', 'bread', 56, 'tata namak']
['milk powder', 'test', 'bread', 56, 'tata namak']
[1, 23, 34, 45, 78, 90]
Traceback (most recent call last):
File "c:\python code\Listsandtuplefunction.py", line 42, in <module>
print(shop_list1.max)
^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'max'
PS C:\python code> ^N
Thanks you for commenting your questions. I will see question and respond you.