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

Python base

时间:2016-08-01 01:38:19      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

//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 user 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 user ‘ 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 proble 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. 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)

 

 

 

 

Python base

标签:

原文地址:http://www.cnblogs.com/wangyaoguo/p/5724339.html

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