在python中写多行语句用加号和反斜杠连接
问题:请问怎样在python中写多行语句
答案:用加好和反斜杠连接多行语句
name = "zzzyk.com"
age = 22
gender = "boy"
str = "Hello, my name is " + \
name + \
". I'm " + \
str(age) + \
"years old " + \
gender
print(str)
# Hello, my name is zzzyk.com. I'm 22years old boy
如果语句换行时包裹在中括号: [], 大括号: {}, 或者括号: (), 中, 则不必反斜杠换行, 如下:
name = "yizuotu.net"
age = 22
gender = "boy"
str = ("Hello, my name is " +
name +
". I'm " +
str(age) +
"years old " +
gender)
print(str)
# Hello, my name is yizuotu.net. I'm 22years old boy