Reputation: 637
I've been looking a this code that uses numpy to reduce the size of a dataframe.
Here's a snippet
if c_min > np.iinfo(np.int8).min and c_max <\
np.iinfo(np.int8).max:
df[col] = df[col].astype(np.int8)
Is the \
there after the <
due to the newline? Like telling python that the if statement is going to continue on the next line? Just wanted to make sure.
Upvotes: 1
Views: 89
Reputation: 21
The '\' (backslash) character is the line continuation character which just tells python that the statement will continue on the next line. So
if c_min > np.iinfo(np.int8).min and c_max <\
np.iinfo(np.int8).max:
df[col] = df[col].astype(np.int8)
could just be re-written as:
if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:
df[col] = df[col].astype(np.int8)
There is no difference between them logically, it is just personal preference.
Docs: https://docs.python.org/3/reference/lexical_analysis.html#explicit-line-joining
Upvotes: 2