zoukankan      html  css  js  c++  java
  • python 学习笔记之基础知识(2)

    1、输入输出:

        输出:print,如下

    >>> print 'Hello World'
    Hello World

        输入:input(),row_input()

    推荐使用row_input(),input()会默认你输入的数据类型是对的,导致一些错误,除非特别需要,尽量用row_input

    >>> name = raw_input("what is you name ?")
    what is you name ?sola
    >>> print name
    sola

    2、字符串

     a、长字符串

        如果要写一个很长很长,要跨越几行的可以使用三个引号,如下:

    >>> print '''what are you laughing at?
    ... I don't know what that mean
    ... sorry !'''

      b、原始字符串

    像“ ” 这些带反斜杠的字符串会有换行,或其他转义效果,所以比如我们要打印一个物件目录时(如d: othing hat)时,会产生不必要的错误

    但原始字符串不会对这些反斜杠有特别对待,原始字符串,只要在字符串前,以r开头即可,如下:

    >>> print 'd: othing hat'
    d:
    othing hat
    >>> print r'd: othing hat'
    d: othing hat

        c、Unicode字符串

    这个细节不太知道,用法和原始字符串差不多,在字符串前加一个u,如下

    >>> print u'hello world'
    hello world

    3、一些函数

    pow(x,y[,z])    #返回x的y次幂(所得结果对z取模)

    round(number[,ndigits])   #根据给定的精度对数字进行四舍五入

  • 相关阅读:
    前端知识总汇
    html基础
    linux密码修改实验
    [ 转 ] 为 phpstorm 自定义默认 Web 服务器
    简易 PHP 教程小记
    EXPORT Man Information for Linux use COMMAND col
    CiSCO 交换机配置 SSH 登陆
    修复已损坏的交换机IMG
    Jupyter Notebook远程服务器配置[转]
    Linux 调节分辨率
  • 原文地址:https://www.cnblogs.com/sola-tester/p/4084344.html
Copyright © 2011-2022 走看看