1. %s % 사용

 >>> test_string = 'SELECT * FROM raw_data WHERE %s = "%s"'

 >>> print(test_string % ('date', '2021-12-31'))

# SELECT * FROM raw_data WHERE date = "2021-12-31"

 

 

 

 

2. format {number} 사용

 >>> test_string = 'SELECT * FROM raw_data WHERE {0} = "{1}"'
 >>> print(test_string.format('date', '2021-12-31'))
# SELECT * FROM raw_data WHERE date = "2021-12-31"

 [ 아래와 같이 사용도 가능함 ]

 >>> test_string = 'SELECT * FROM raw_data WHERE {1} = "{0}"'
 >>> print(test_string.format('2021-12-31', 'date'))
# SELECT * FROM raw_data WHERE date = "2021-12-31"

 

 

 

3. format {name} 사용

 >>> test_string = 'SELECT * FROM raw_data WHERE {column} = "{data}"'

 >>> print(test_string.format(column='date', data='2021-12-31'))

# SELECT * FROM raw_data WHERE date = "2021-12-31"

 

 

+ Recent posts