在Python中,print函數的format方法可以用于格式化輸出字符串。以下是一些常見的轉義字符使用技巧:
name = "Alice"
print("Hello, {0}!".format(name))
name = "Alice"
age = 30
print("My name is {0} and I am {1} years old.".format(name, age))
pi = 3.14159265359
print("The value of pi is {0:.2f}".format(pi))
percentage = 0.75
print("The percentage is {0:.2%}".format(percentage))
print("This is a line with\na new line character")
print("This is a line with\ttab character")
這些是一些常見的Python print format函數的轉義字符使用技巧,可以幫助你更靈活地格式化輸出字符串。