日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python上个手

發布時間:2023/12/1 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python上个手 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ??Python,由吉多·范羅蘇姆(Guido van Rossum)在1989打發圣誕節放假時間的一門“課余”編程項目,至今已有二十多年的歷史,語法簡潔清晰,深受喜愛;

  • 小窺
    # 查看版本 python -V # 輸出 print "hello" # 輸入 str = raw_input("press any key") print str# 注釋 print "www.cnblogs.com" # link # 幫助 dir(list) help(list)
  • 變量
    # 無需聲明和刪除,直接賦值;type為內置函數,查詢類型; a = 10 print a,type(a) a = “hello” print a,type(a) a += “ word” print a,type(a)
  • 列表、元組和詞典
    ##### # 1. 列表:list,數據如同STL <list>,下標從0開始,支持添加刪除 province = ['GuangDong', 'ZheJiang', 'HeNan', 'XinJang', 'HeiLongJiang'] print province[2] province.append(‘HuBei’) delete province[1]# 訪問支持:[下限:上限:步長],上限不包括在內 print province[:3] # idx from 0 to 7 print province[3:] # idx from 3 to end print province[0:5:2] # from 0 to 4 with 2 steps print province[3:0:-1] # from 2 to 1 with -1 steps print province[-1] # the last one print province[-3] # the second one from last ##### # 2. 元組:Tuples,如同list,不過不能改變;如12個月英文名之類的常量 days = ('Morning','Afternoon','Night') print days,type(days)# 字符串是一種triple str = “Hello world” print str[2:5]##### # 3. 詞典:Dictionaries, 如同hash, 元素結構為 key:value;如成績 stu_score = {'ZhangSan':34,'LiSi':98, 'WangWu':99}# 新增key:value str_score['LiLei'] = 100# 刪除key delete str_score['ZhangSan']# 檢查 if str_score.has_key(‘HanMeiMei’):print “got HanMeimei else print “not find HanMeiMei# 打印所有key,values? print stu_score.keys(),str_score.values() values = stu_score.values() values.sort() print values,length(values)
  • 循環
    # Python中語句后無“;”結尾;無“{}”,通過TAB(4個空格) # 1. while a = 0 while (a < 10)a += a+1;print a # 2. if y = True if y == True:print “y is true” elif y == False:print “y is false” else:print “value of y is error.”#3. For tmp = [1,’a’,’sdfa’,242] for value in tmpprint value# 判斷符號 >, >=, <, <=, ==, !=, in
  • 函數
    # 定義函數show def show(list, info)for entry in list:print entryreturn input(info) + 1 # input輸出數字 # 表傳指針,bulid-in傳值 list = [1,2,3] info = “press num: “ def show (list, info)list[1]=3info = “changed” show(list, info) print list,info

  • # 定義類 class Shapedef __int__(self, x, y): # 構造self.x = xself.y = ydef area():print self.x * self.y shape = Shape(100,20) class Square(Shape) # 繼承def __int__(self, x):self.x = self.y = x# 對象詞典 class_dic = {} class_dic[“Shape”] = Shape(100,20) class_dic[“Square”] = Square(100,20) print class_dic[“Shape”].area print class_dic[“Square”].area
  • 模塊
    # 模塊:只定義集(庫),比如變量、函數和類 # 可以自定義模塊和模塊包 import test_module import dir.module # 相同類型放一個目錄
  • 文件操作
    Ofile = open(‘file’, ‘r’) Ofile.seek(45,0) # 支持seek、tell, readline, readlins, wirte, close
  • 異常處理
  • try:a = input(“press characters”) except NameError:print “input a num”

    ?

    [Reference]

    http://zh.wikipedia.org/zh-cn/Pythonhttp://www.sthurlow.com/python/http://www.cnblogs.com/vamei/archive/2012/05/28/2521650.html

    轉載于:https://www.cnblogs.com/sunjerdege/p/3387170.html

    總結

    以上是生活随笔為你收集整理的Python上个手的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。