勤学思培训网GEZYDK
  • 总算懂了python如何换行

    Python中一般是一行写完所有代码,如果遇到一行写不完需要换行的情况,那么python如何换行呢?一起来了解下吧: python如何换行
    [图片0] 1.在该行代码末尾加上续行符“ ”(即空格+); test = 'item_one' 'item_two' 'tem_three' 输出结果:'item_oneitem_twotem_three' 2.加上括号,() {} []中不需要特别加换行符: test2 = ('csdn ' 'cssdn') 输出结果:csdn cssdn if...and: if (where there is a will and there is a way) 多次未输出结果 test3 =('Hello' ' ' 'world') 输出结果:Hello world Python换行的方法 1.用反斜杠链接多行代码,示例输出:55 a = 22 + 33 print a 2.用小括号括起来,示例输出:55 a = (22+ 33) print a 提示:针对较长字符串分成多行书写的还有一种简单的方法:用三个单引号,但是该方法只针对字符串有用。下面代码输出:
    [图片1] 32 + 45 a = '''32 + 45''' print a Python字符串如何换行 if __name__ == '__main__': #第一种:三个单引号 print '''我是一个程序员 我刚开始学习python''' #第二种:三个双引号 print """我是一个程序员 我刚开始学习python""" #第三种:结尾 print"我是一个程序员, 我刚开始学python" python代码过长如何换行 python代码换行就是每行后面加个 举个栗子: time = "2017" print "one" + "," + "two" + ",three" + "," + time 打印出来就是: one,two,three,2017 再举一个栗子: print "this line is toooooooooooo long" 打印出来: this line is toooooooooooo long