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

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

转载于:https://www.cnblogs.com/sola-tester/p/4084344.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值