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

    >>> 

  • 相关阅读:
    获取指定字符传的长度或者高度
    检测身份证号码是否合法
    tabbar添加小红点
    单例的简单构造
    iOS程序内发短信
    多项式加法运算 使用链表实现
    链表的数组实现
    使用链表实现堆栈
    使用链表实现堆栈
    求最大子列和的几种方法
  • 原文地址:https://www.cnblogs.com/duneF/p/6973488.html
Copyright © 2011-2022 走看看