Search code examples
pythonoperators

meaning of "%" in printing the result of adfuller in Python


There's a % in the following code, which is from ARIMA Model in Python .

from statsmodels.tsa.stattools import adfuller
from numpy import log

result = adfuller(df.value.dropna())
print('ADF Statistic: %f' % result[0]) 
print('p-value: %f' % result[1])

I'm confused to what the % does in the print statement (last line). What does it do to the result? Or, does it represent mod?

Thanks!


Solution

  • The % symbol is related to string interpolation rather then the print. It is a way to format string. You can read here more about it.

    It is just one of many ways to format strings in python:

    1. “Old Style” String Formatting (% Operator)
    2. “New Style” String Formatting (str.format)
    3. String Interpolation / f-Strings (Python 3.6+)
    4. Template Strings (Standard Library)