码迷,mamicode.com
首页 > 编程语言 > 详细

python 学习笔记之基础知识(2)

时间:2014-11-09 06:15:02      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:ar   使用   sp   数据   on   bs   python   学习   nbsp   

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、原始字符串

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

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

>>> print ‘d:\nothing\that‘
d:
othing hat
>>> print r‘d:\nothing\that‘
d:\nothing\that

 

    c、Unicode字符串

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

>>> print u‘hello world‘
hello world

 

3、一些函数

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

 

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

python 学习笔记之基础知识(2)

标签:ar   使用   sp   数据   on   bs   python   学习   nbsp   

原文地址:http://www.cnblogs.com/sola-tester/p/4084344.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!