This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[2, 4, 6, 7, 10, 12, 13, 15, 17] | |
[2, 4, 6, 8, 10, 12, 13, 15, 17] | |
[2, 4, 6, 8, 10, 12, 14, 16, 18] | |
['Code Refer', 4, 6, 8, 10, 12, 14, 16, 18] | |
Traceback (most recent call last): | |
File "Listedit.py", line 21, in <module> | |
list_1[11] = 20 | |
IndexError: list assignment index out of range |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list_1 = [2, 4, 6, 7, 10, 12, 13, 15, 17] | |
print(list_1) | |
# Returns new value for 4th element | |
list_1[3] = 8 | |
print(list_1) | |
# Returns new value for 7th, 8th & 9th element |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
['d', 'e', 'r'] | |
['e', 'f', 'e', 'r'] | |
['c', 'o', 'd'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list_1 = ['c', 'o', 'd', 'e', 'r', 'e', 'f', 'e', 'r'] | |
# Return only 3rd,4th,5th items of list. | |
print(list_1[2:5]) | |
# Return values from 6th item to last item of list | |
print(list_1[5:]) | |
# Return values from first item of list to 4th element | |
print(list_1[:3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e | |
r | |
Traceback (most recent call last): | |
File "NegativeIndex.py", line 9, in <module> | |
print(list_1[-10]) | |
IndexError: list index out of range |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list_1 = ['c', 'o', 'd', 'e', 'r', 'e', 'f', 'e', 'r'] | |
# Print using Negative Indexing | |
print(list_1[-2]) | |
print(list_1[-5]) | |
# provided out of range index | |
print(list_1[-10]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d | |
c | |
r | |
Traceback (most recent call last): | |
File "Accesselements.py", line 11, in <module> | |
print(list_1[2.0]) | |
TypeError: list indices must be integers or slices, not float |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list_1 = ['c', 'o', 'd', 'e', 'r', 'e', 'f', 'e', 'r'] | |
# Index value as integer | |
print(list_1[2]) | |
print(list_1[0]) | |
print(list_1[4]) | |
# Index value as float |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List of integers | |
list_1 = [2, 3, 7, 9, 5] | |
# List of strings | |
list_2 = ["List", "Tuple", "Python"] | |
# List of different data types | |
list_3 = ["Coderefer", 23, 9.5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NumberFormat us=NumberFormat.getCurrencyInstance().format(payment); |
NewerOlder