zoukankan      html  css  js  c++  java
  • 9.11 前9习题

    1.print 

    (1)打印的第一句 。。。。

    1 print " Hello World! "

    注意""和''的使用

    1 print "i'm paul"   #
    2 
    3 print 'i'm paul'  # 错   改为 'i \'m paul'

    以及""" """和''' '''的使用

    1 print  """
    2 
    3 Hello World!
    4 
    5 Hello World!
    6 
    7 Hello World!
    8 
    9 """

    (2)逗号

    print "hello world ",'abc'
    
    print "i am paul "

    结果:

    hello world abc

    i am paul

    print "hello world "  'abc'
    
    print "i am paul "

    结果:

    hello world abc

    i am paul

    print "hello world" ' abc',
    print "i am paul"

    结果:

    hello world abci am paul

    print "hello world" ' abc',
    "i am paul"

    语法错误

    (3)运算符号

    print "now i will count the eggs:"
    print 3+1+2-5+4%2-1/4
    print 3+2>4-2

    结果:

    now i will count the eggs:

    1

    True

    (4)变量及打印

    name = "paul"
    age = 20
    height = 70
    
    print "let's talk about %s"%name
    print "he's %d years old"%age
    print "he's %d inches tall"%height
    
    
    print "let's talk about %r"%name
    print "he's %r years old"%age
    print "he's %r inches tall"%height

    print "if i add %d and %d,i get %d."%(age,height,age+height)

    let's talk about paul

    he's 20 years old

    he's 70 inches tall

    let's talk about "paul"

    he's 20 years old

    he's 70inches tall

    if i add 20 and 70,i get 90

    x = "there are %d types of people."%10
    print x 
    
    print "i said :%r "%x
    
    y =  "isn't that joke so funny? %r"
    z = False
    
    print y%z
    
    a = "this is the left of"
    b = "a string with a right side"
    
    print a + b

    结果:
    there are 10 types of people.

    i said :there are 10 types of people.

    isn't that joke so funny?False

    this is the left of a string with a right side

    print "ab " *10

    结果:
    ab ab ab ab ab ab ab ab ab ab

    formatter = "%r %r %r"
    
    print formatter %(1,2,3)
    print formatter %("one","two","three")
    print formatter %(True,False,True)
    print formatter %(
       "i had this string",
       "that you could ",
       "type  up right"     
      
    )

    1 2 3
    'one' 'two' 'three'

    True False True

    'i had this string' 'that you could' ' type up right'

    1 a = "a\nb\nc\n"
    2 print a 

    结果:

    a

    b

    c

  • 相关阅读:
    Unity 项目中委托Delegate用法案例
    如何让jpa 持久化时不校验指定字段
    Unity 3D光源-Spot Light聚光灯用法详解、模拟手电筒、台灯等线性教程
    unity 实现调用Windows窗口/对话框交互
    Unity 3D光源-Point Light点光源详解/灯泡、模拟灯光效果教程
    unity ugui Toggle Group详解(Chinar出品、简单易懂)
    Unity 3D UGUI Toggle用法教程
    Unity3D UGUI下拉菜单/Dropdown组件用法、总结
    CI/CD学习一
    智慧校园整体架构
  • 原文地址:https://www.cnblogs.com/fanyear/p/4802297.html
Copyright © 2011-2022 走看看