Created
February 5, 2019 06:42
-
-
Save v/ad15e5fd4e4e2f9c4c3ec64b721057b9 to your computer and use it in GitHub Desktop.
Examples of string formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command = "SELECT * FROM whatever" | |
print(command) | |
fieldname = "age" | |
command = "SELECT " + fieldname + " from whatever" | |
print(command) | |
fieldname = 'age' | |
fieldname2 = 16 | |
command = "SELECT %s from whatever WHERE %s=%d" % (fieldname, fieldname, fieldname2) | |
# SELECT age FROM whatever WHERE age=16 | |
print(command) | |
command = "SELECT {fieldname} FROM whatever WHERE {fieldname}={fieldname2}".format(fieldname='name', fieldname2='Divya') | |
print(command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment