• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    馮唐--python學習日記(1)

    發布: 2007-7-04 20:06 | 作者: admin | 來源:  網友評論 | 查看: 24次 | 進入軟件測試論壇討論

    領測軟件測試網

    1、python是大小寫敏感的語言

    2、在書寫函數時需定義

    例:

    def  functionname(parameter1[,]):

    3、書寫控制塊的時候需要代碼縮進一個Tab鍵值,一個縮進層等于四個空格,八個空格等于一個制表符。

    4、當遇到非縮進代碼行時,函數定義結束。

    5、控制語句后面都需跟冒號(:),并且控制語句中的語句需要縮進一層。

    例(1):

    >>> def MyFunction(MyNember):
    ...     if(MyNember == 855):
    ...             print "right"
    ...     else:
    ...             print "worst"
    ...
    >>> MyFunction(5)
    worst
    >>> MyFunction(855)
    right
    >>>

    例(2):

    >>> FoodTuple=("Spam","Egg","Sausage")
    >>> FoodTuple=list(FoodTuple)
    >>> FoodList
    ['Spam', 'Egg', 'Sausage']
    >>> FoodList[2]
    'Sausage'
    >>> FoodList[2]="Spam"
    >>> NewFoodTuple=tuple(FoodList)
    >>> NewFoodTuple
    ('Spam', 'Egg', 'Spam')
    >>>

    例(3):

    >>> PhoneDict=
    >>> EmptyDict={}
    >>> PhoneDict["bob"]
    '555-1212'
    >>> PhoneDict["cindy"]="867-5309"
    >>> print "phone list:",PhoneDict
    phone list: {'bob': '555-1212', 'cindy': '867-5309', 'fred': '555-3345'}
    >>> PhoneDict["luke"]
    Traceback (most recent call last):
      File "", line 1, in ?
    KeyError: 'luke'
    >>> PhoneDict.get("joe","unknown")
    'unknown'
    >>> PhoneDict.get("bob","unknown")
    '555-1212'
    >>>

    >>> DialAJoe=PhoneDict.get("joe",None)
    >>> DialAJoe
    >>> print DialAJoe
    None
    >>> DialAJoe=PhoneDict.get("bob",None)
    >>> print DialAJoe
    555-1212
    >>>

    6、list(),tuple()可以轉換元組和列表

    list為列表,tuple為元組

    7、變量,常量等基本元素單位不定義就可以使用。和其他的語言不同。

    例(4):

    >>> import string
    >>> def CountWords(Text):
    ...     WordCount={}
    ...     CurrentWord=""
    ...     Text = Text+"."
    ...     PlecesOfWords = string.letters + "'-"
    ...     for CharacterIndex in range(0,len(Text)):
    ...             CurrentCharacter = Text[CharacterIndex]
    ...             if (PlecesOfWords.find(CurrentCharacter)!= -1):
    ...                     CurrentWord = CurrentWord + CurrentCharacter
    ...             else:
    ...                     if(CurrentWord!=""):
    ...                             CurrentWord = string.lower(CurrentWord)
    ...                             CurrentCount = WordCount.get(CurrentWord,0)
    ...                             WordCount[CurrentWord]=CurrentCount+1
    ...             CurrentWord = ""
    ...     return(WordCount)
    ...     if(__name__=="__main__"):
    ...             TextFile = open("poem.txt","r")
    ...             Text = TextFile.read()
    ...             TextFile.close()
    ...             WordCount = CountWords(Text)
    ...             SortedWords = WordCount.keys()
    ...             SortedWords.sort()
    ...             for Word in SortedWords:
    ...                     print Word,WordCount[Word]
    ...
    例(5):

    >>> import math
    >>> class Point:
     def __init__(self,X,Y):
      self.X = X
      self.Y = Y
     def DistanceToPoint(self,OtherPoint):
      "Returns the distance from this point to another"
      SumOfSquares = ((self.X-OtherPoint.X)**2)+
        ((self.Y-OtherPoint.Y)**2)
      return math.sqrt(SumOfSquares)
     def IsInsideCircle(self,Center,Radius):
      """Return 1 if this point is inside the circle,
      0 otherwise"""
      if (self.DistanceToPoint(Center)<
       return 1
      else:
       return 0

    >>> PointA= Point(3,5)
    >>> PointB= Point(-4,-4)
    >>> print "A to B:",PointA.DistanceToPoint(PointB)
    A to B: 11.401754251
    >>> print "B to A:",PointB.DistanceToPoint(PointA)
    B to A: 11.401754251
    >>> CircleCenter = Point(3,3)
    >>> print "A in circle:",PointA.IsInsideCircle(CircleCenter,5)
    A in circle: 1
    >>> print "B in circle:",PointB.IsInsideCircle(CircleCenter,5)
    B in circle: 0
    >>>

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>