python 基础教程之1 运算,字符串,print函数 与 input函数

linux python基础教程 python 3.5

Posted by ivo on March 20, 2018

0x01 运算

  • 平方
    >>> 2 ** 2
    4
    
  • 立方
    >>>pow(2,3)
    8
    
  • 四次方
    >>>pow(2,4)
    16
    
  • 整除取整数
    >>>5 // 3
    1
    
  • 取余
    >>>5%3
    2
    

    0x02 字符串

  • 单引号 双引号等的特殊字符需要使用转义字符
    >>>'this is book '
    'this is book'    
    >>> 'He\'s book'
    "He's book"
    

    0x03 print函数 与 input函数

    >>>print(1+1)
    2
    >>> print('hello\nworld')
    hello
    world
    
    >>> input('enter something please:')
    enter something please:good is good
    'good is good'
    
  • input用法示例(注意input里面的提示语一定要加引号’‘)
    >>> word = input(please input something:)
    File "<stdin>", line 1
      word = input(please input something:)
                              ^
    SyntaxError: invalid syntax
    
    >>> word = input('please input something:')
    please input something:god
    >>> x = 'ttt'
    >>> print(x + word)
    tttgod