简体   繁体   中英

What does <\ mean in Python?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM