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])   #根据给定的精度对数字进行四舍五入

  • 相关阅读:
    Android EditText内容监听
    Android模仿QQ空间图片上传——原理
    PHP新手入门1——表单
    linux下ftp常用命令
    TextView所有属性
    iOS开发-删除字典中的null
    去除导航栏下方的横线
    应用的启动视图 LauchView
    App所需申请资料
    应用本地化
  • 原文地址:https://www.cnblogs.com/sola-tester/p/4084344.html
Copyright © 2011-2022 走看看