美文网首页
笨办法学python第8课

笨办法学python第8课

作者: 3ab9db71c244 | 来源:发表于2018-08-31 16:53 被阅读7次
    formatter = "{} {} {} {}"  #将
    
    print(formatter.format(1, 2, 3, 4))  #str.format.()   将数值1234嵌入formatter之中
    
    print(formatter.format("one", "two", "three", "four"))  ##str.format.()   将数值one..嵌入formatter之中
    
    print(formatter.format(True, False, False, True))#将布尔值嵌入
    
    print(formatter.format(formatter, formatter, formatter, formatter))   #将自身嵌入
    
    
    print(formatter.format(  #将四句话去嵌入
        "try your",
        "own text here",
        "maybe a poem",
        "or a song about fear"
    ))
    
    
    运行结果:
    /Users/tongshiba/PycharmProjects/ex3/test8.py
    1 2 3 4
    one two three four
    True False False True
    {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
    try your own text here maybe a poem or a song about fear
    
    Process finished with exit code 0
    
    Study Drills练习题
     checks, write down your mistakes, and try not to make the same mistakes on the next exercise.In other words, repeat the Study Drills from Exercise 7
    
    done,代码是:
    formatter = "{}{}{}{}{}{}"
    print(formatter.format("c","h","e","e","s","e"))
    
    formatter = "{}{}{}{}{}"
    print(formatter.format("b","u","r","g","e"))
    
    
    Common Student Questions常见疑问:
    1.Why do I have to put quotes around "one" but not around True or False? 
    Python recognizes True and False as keywords representing the concept of true and false. If you put quotes
    around them then they are turned into strings and won’t work. You’ll learn more about how these work in Exercise 27.
    
    2.Can I use IDLE to run this?
     No, you should learn to use the command line. It is essential to learning programming and is a good place to start if you want to learn about programming. IDLE will  fail for you when you get further in the book.

    相关文章

      网友评论

          本文标题:笨办法学python第8课

          本文链接:https://www.haomeiwen.com/subject/ujqewftx.html