zoukankan      html  css  js  c++  java
  • python初体验

    hello word

    zhangfeng:~ zhangfeng$ python
    Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
    [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> help
    Type help() for interactive help, or help(object) for help about object.
    >>> print "hello word!"
    hello word!
    

    以下为一错,已正确书写方法

    >>> x=input("x:")x:34
      File "<stdin>", line 1
        x=input("x:")x:34
                     ^
    SyntaxError: invalid syntax

    以上为错误书写方式
    >>> x=input("x:")
    x:
    34

     >>> y=input("y:")

     y:42

     >>> print x*y

     1428

     >>> 2**3

     8

     >>> pow(2,3)

     8

     注意此处为pow(2逗号3)传入2和3的意思调用pow函数

     >>> abs(-10)

     10

    abs为absolute的简写,绝对| absəluːt

    >>> import math

    >>> math.floor(32.6)

    32.0

    >>> int(math.floor(32.6))        此处类同于java中的将浮点类型强制转换成int整数类型

    32

    >>> foo=math.sqrt    将math.sqrt的对象赋给foo,

    >>> foo(9)        foo(9)就等于math.sqrt(9)    sqrt计算平方根

    3.0

    >>> 

  • 相关阅读:
    ffmpeg
    HDU 1031 Design T-Shirt
    HDU 1029 Ignatius and the Princess IV
    HDU 1022 Train Problem I
    HDU 1017 A Mathematical Curiosity
    HDU 1015 Safecracker
    HDU 1002 A + B Problem II
    HDU 1070 Milk
    高精度算法(一)
    codeblocks 使用心得
  • 原文地址:https://www.cnblogs.com/duneF/p/6973488.html
Copyright © 2011-2022 走看看