Python 学习笔记(一):numbers and expressions

Numbers and Expressions 

     1.0/2.0 

     =0.5 

     1/2 

     =0      

     another alternative, if you are programming with command line 

Large Integers 

2147483647  to -2147483648 

     larger, we need to use longs: L 

Hexadecimals and Octals 

     0xAF=175 

     010=8 

Getting Input from the User 

     x=input("x:") 

Deal with imaginary and floats numbers 

     import cmath 

Strings 

     print double quotes 

     " helloworld!" 

     it shows the same for these cases 

     but for some cases the double quotes and single quotes make difference 

     like  

     "Let's go!" 

     and '"hellopetershe said' 

      

     examples: 

          'let's go' 

          will not work 

          but 'let\'s go' will work finely 

          the same as the former: 

          "\"helloworld\" she said" 

          will work finely 

input vs. raw_input 

         input suppose that what you have entered is a valid python expression: 

          nameinput("what is your name?") 

          print "Hello,"+name +"!" 

          if we input Zhichaoerror will come out but "zhichao" will not pop out error. 

          for raw_inputwe will not have such problems. 

          raw_input treat all input as raw data and puts it into a string. 

Slash 

         like \n = <enter> 

     if we want to input \ the way to do that is \\ 

     but for long inputthis will be a lot of work. 

    raw stringsare used at such kind of cases 

     print r'C:\nowhere' 

     but the last character can not be backslash 

     but what if you need a backslash at last 

     here is a simple solution: 

     print r'C:\program\foo\bar' '\\' 

     C:\program\foo\bar\ 

function 

abs() 

cmath.sqrt() 

float(): convert the string or number to a floating-point number 

help() 

input() 

int() 

long() 

math.ceil(number): return the ceiling of a number as float 

math.floor(number): floor of a number as a float 

math.sqrt() 

pow(x,y[,z]) 

raw_input(pompt) 

repr(objectreturn a string representation of a value 

round(number,ndigits]) round a number to a given precision 

str(objectconvert a value to a string

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值