Jan-22-2020, 04:12 PM
Python works in 0 based index. I have tried to change the python to work in 1 based index.
python_file_A.py
python_file_B.py
While running python_file_B.py,
Actual Output :
Before function change : b
After function change : b
Expected Output :
Before function change : b
After function change : a
After function change the example_list[1] should give 'a' as output which is example_list[0]
Without using class be preferred. Kindly help to resolve this.
reference links below,
https://stackoverflow.com/questions/1172...ex-0-based
http://defcraft.blogspot.com/2007/04/n-b...-list.html
python_file_A.py
1 2 3 4 |
def __getitem__( self , index): return self . list [index - 1 ] def __setitem__( self , index, value): self . list [index - 1 ] = value |
1 2 3 4 |
example_list = [ 'a' , 'b' , 'c' , 'd' , 'e' ] print ( "Before function change : " ,example_list[ 1 ]) from python_file_A import * print ( "After function change : " ,example_list[ 1 ]) |
Actual Output :
Before function change : b
After function change : b
Expected Output :
Before function change : b
After function change : a
After function change the example_list[1] should give 'a' as output which is example_list[0]
Without using class be preferred. Kindly help to resolve this.
reference links below,
https://stackoverflow.com/questions/1172...ex-0-based
http://defcraft.blogspot.com/2007/04/n-b...-list.html