This is my code:
a=[1,2,3]
print(a)
a=a.append(1)
print(a)
Output:
[1, 2, 3]
None
Why was None
printed instead of [1, 2, 3, 1]
?
I used to try some stuff with pandas DataFrames and I remember a parameter named inplace.
import pandas as pd
import numpy as np
df = pd.DataFrame(np.arange(12).reshape(3, 4),
columns=['A', 'B', 'C', 'D'])
print(df)
print(df.drop(['B', 'C'], axis=1))
df1 = df.drop(['B', 'C'], axis=1)
print(df)
print(df1)
Output:
A B C D
0 0 1 2 3
1 4 5 6 7
2 8 9 10 11
A D
0 0 3
1 4 7
2 8 11
A B C D
0 0 1 2 3
1 4 5 6 7
2 8 9 10 11
A D
0 0 3
1 4 7
2 8 11
It has been said in this answer that it's harmful to use inplace=True
. So, I got habituated to assigning the new dataframe to a new variable (or re-assigning to same variable). So, I thought that lists work similar to pandas DataFrame w.r.t. inplace concept... but I don't think that's the case after reading my output for a.append(). Can you please explain about this in detail?