设为首页 加入收藏

TOP

Python Base One(一)
2017-09-30 17:16:52 】 浏览:6936
Tags:Python Base One

//this is my first day to study python, in order to review, every day i will make notes (2016/7/31)

1. In python , there are many bulit-in funcation. you can use follow to find out hou many built-in funcation:

    dir(__builtins__)

    if you want get BIF detail, you can use follow code:

    help(……)    such as help(input),int()

 

2. In python, you should be care to indent, if not , it will appear a lots error.

    such as follow ,because indent error ,it will appear an error:

    temp = input('input a num you want:')
    guess = int(temp)
    if guess == 8:
    print('you are right')
    else:
           print('you are wrong')

 

3. In python , when you define variable ,uppercase and lowercase is different.

    such as:

    temp = 'roy'

    Temp = 'wyg'

    temp and Temp is not same variable

 

4. In python , if you want to use ' in a string ,you can user escape charcters : \

    such as:

    print('Let\'s go!')

 

5. In python , origin string is userful , maybe the follow result is not  you except

    such as :

    str = 'c:\now\data'

    print(str)

    result is :

    c:

    ow\data

    you can solve this problem by str = r'c:\now\data' ,this code is equal to str = 'c:\\now\\data'

    when you print(str), the result will be c:\now\data

 

6. In python , if a string , you want to change row ,you can user '''  ,if you not user ''' and change row ,it will appear an error

    such as:

    str = '''this

    is

    me'''

    print(str)

    the result is :

    this

    is 

    me 

 

7. In python , import module , such as if you want  a rand num , range is 1-10 and type is int ,how to achieve it

   import random

   randnum = random.randint(1,10)

 

//this is second day to study python(2016/8/1)

8. In python , we can see 'e' as 10

    such as:

    1.5e4 == 15000.0

 

9. In python , type conversion is userful , the follow is base conversion

    float or string -> int

    such as :

    a = '26'    b = int(a)   print(b) -> 26

    a = 'qq'    b = int(a)   error

    a = 3.14  b = int(a)    print(b) -> 3

    ----------------------------------------

    int or string -> float

    such as:

    a = '26'  b = float(b)  print(b) -> 26.0

    a = 'qq'  b = float(b)  error

    a = 26   b = float(b)   print(b) -> 26.0

    ------------------------------------------

    int or float -> str

    such as:

    a = 26  b = str(a)  print(b) -> '26'

    a = 3.14&nb

首页 上一页 1 2 3 4 5 6 下一页 尾页 1/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python自动化运维之1、Python入门 下一篇python中os模块的常用接口和异常..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目