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

笨办法学python第6课

作者: 3ab9db71c244 | 来源:发表于2018-08-31 16:07 被阅读35次
    types_of_people = 10  #变量为10
    
    x = f"there are  {types_of_people} types of people" #将f-string 赋值给x
    
    binary = "binary"  #将字符串赋值给binary
    
    do_not = "don't"  #将字符串赋值
    
    y = f"those who know {binary} and those who {do_not}."  #将f-string 赋值给y
    
    
    print(x)  #打印x
    print(y)
    
    print(f"i said: {x}")  #打印f-string
    
    print(f"i also said: {y}")   #打印f-string
    
    hilarious = False  #布尔值为false
    
    joke_evaluation = "isn't that joke so funny!{}"  #将字符串赋值给joke evaluation
    
    print(joke_evaluation.format(hilarious))  #.format()格式
    
    w = "this is the left side of...."  #将字符串赋值给w
    
    e = "a string with a right side."
    
    print(w+e)  #打印
    
    运行结果:
    /Users/tongshiba/PycharmProjects/ex3/test6.py
    there are  10 types of people
    those who know binary and those who don't.
    i said: there are  10 types of people
    i also said: those who know binary and those who don't.
    isn't that joke so funny!False
    this is the left side of....a string with a right side.
    
    
    练习题
    1. Go through this program and write a comment above each line explaining it.
    #做注解 done
    2. Find all the places where a string is put inside a string. There are four places.
    
    
    3. Are you sure there are only four places? How do you know? Maybe I like lying.
    
    sure
    
    4. Explain why adding the two strings w and e with + makes a longer string
    
    告诉我们字符串之间可以做加法
    
    
    Common Student Questions常见问题
    1.Why do you put ' (single-quotes) around some strings and not others? 
    Mostly it’s because of style,but I’ll use a single-quote inside a string that has double-quotes. Look at lines 6 and 15 to
    see how I’m doing that.
    
    2.If you thought the joke was funny could you write hilarious = True? 
    
    Yes, and you’ll learn more about these boolean values in Exercise 27.

    相关文章

      网友评论

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

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