第一章,重点总结

1.长整数:>>>100000000000L,否则报错

2.获取用户输入:input(“input your string:”),raw_input(“input your string:”)

3.函数:绝对值:>>>abs(-10);输出10,四舍五入:>>>round(1.0/2.0);输出1.0

4.模块:sqrt,计算平方根,import cmath(复数模块)>>>sqrt(-1);输出1j

5.字符串:>>>"Hello,world";输出:'Hello,world',>>>'Hello,world';--'Hello,world',

    >>>"Let's go!";--"Let's go!" ,>>>'"Hello.world" she said';--'"Hello.world!" she said'

     字符串表示:str和repr

    >>>print repr("Hello,world!")

    'Hello,world!'

    >>>print repr(10000L)

    100000L

    >>>print str("Hello,world")

    Hello,world

    >>print str(100000L)

    100000

  input和raw_input

    name=input("What is your name?")

    print "Hello,"+name+"!"

    看起来完全合法,但是报错

    What is your name?Gumby

    ...

    NameError:name'Gumby' is not defined

    问题在于imput会假设用户输入的是合法的Python表达式

    What is your name? "Gumby"

    Hello,Gumby!

    输入带""的输入成功,然而不够友好,因此,需要使用raw_input函数,它会把所有输入当做原始数据(raw data),然后放入字符串

    >>>input("Enter a number:")

    Enter a number:3

    3

    >>>raw_input("Enter a number:")

    Enter a number:3

    '3'

    平时应用应该尽量使用raw_input,除非特别要求

  长字符串:

    '''sdfsdfsdf........

    ......sdfsdf''',

    """sdfs;dfklsd...

    ...sdgasdifasl"""

  原始字符串:(可以不用转义)

    >>>print r'c:asdqwewersdgfs'

    特例:反斜杠在最后

    >>>print r'c:asdqwewersdgfs' '\'

    >>>c:asdqwewersdgfs

  Unicode字符串:

    >>>u'Hello,world'

    u'Hello,world'

    

原文地址:https://www.cnblogs.com/yhcreak/p/5314820.html