python中\t的用法

\t会把前面的字符串补全8位,或8的整数倍

  • \t前面没有字符,会空四个位置,相当于一个Tab

  • \t前面的字符<4,则下一个字串会跳过前4个位置(一个Tab),从第5个位置开始

  • \t前面的字符>=4且<8,则下一个字符串会跳过前8个位置(两个Tab),从第9个位置开始

  • \t前面的字符>=8且<12,则下一个字符串会跳过前12个位置(三个Tab),从第13个位置开始

  • \t前面的字符>=12且<16,则下一个字符串会跳过前16个位置(四个Tab),从第17个位置开始

  • ·······

  • print("\thahaha")
    print("hi\tpretty")
    print("hhh\tnihao")
    print("abcd\tefg")
    print("hello\tnihao")
    print("have a good\tday")
    print("beautiful\tgirl")
    print("have a good day\teveryone")
    print("take a chance\thahaha")
    

    输出结果

    	hahaha
    hi	pretty
    hhh	nihao
    abcd	efg
    hello	nihao
    have a good	day
    beautiful	girl
    have a good day	everyone
    take a chance	hahaha
    

    作者:油葵籽

    物联沃分享整理
    物联沃-IOTWORD物联网 » python中\t的用法

    发表回复