python第十次課 2018 04 22

2021-08-19 05:11:20 字數 3798 閱讀 9476

##複習

class a(object):

pass

def main():

a a();

if __name__ == '__main__':

main()

#format 格式化

#count  統計

#isdecimal 是否是十進位制的數字

#split 分割

#encode 編碼  (a).decode(『gbk』).encode(『utf-8')

#isalpha 是否是字母

#isspace是否是空格

#isdigit 是否是數字

#strip 去掉首位的空格

#join   加入 (合併,聚合)  list,dict(可迭代物件)

#index 下標

#startswith  以什麼開頭

#find  查詢 返回值 ([1])找到的該元素的下標,找不到返回-1

#replace 替換

#endswith 以什麼結尾

#lower 小寫

#upper 大寫

#isalnum 數字或者字母

#captitalize 首字母大寫

#lstrip 左邊的去空格

#rstrip 右邊的去空格

#列表  [1,2,3].sort()

#sort  排序

#count 統計

#copy 複製

#remove 刪除

#clear 清空

#pop 刪除哪個元素 預設末尾

#index 下標

#extend 拓展

#reverse反序

#insert 插入

#字典 a = dict()

#items 遍歷每個元素

#copy 複製

#update 更新,合併

#fromkeys

#values 代表所有的值

#keys 代表所有的keys

#clear清除

#pop 刪除 x.pop(a),刪除a的value值

#get根據key得到value

#setdefault 獲取值   x.setdefault("j",20) 獲取20  會增加到字典

#popitem 清除遍歷

x = dict(a=1,b=2)

y = dict(c=3,d=4)

x.update(dict(m=100))

x["n"] = 200

print(x.setdefault("j",20))

print(x)

import codecs

with codecs.open("1.txt","r") as f:

f.write()

f.writelines() #list

f.readlines() #讀取所有行

f.read() # 整個檔案作為乙個字串讀取

f.readline() #讀取一行(一行一行讀取)

f.seek #偏移量 0代表開頭 1代表當前位置 2代表結尾

f.truncate()#不寫預設清空所有

f.tell()  #返回檔案的指標在哪個位置

f.closed()#關閉檔案

f.encoding #檔案的編碼

f.fileno #檔案的描述符

#常用模組

#, ]}

import json

def test():

result = dict()

try:

print(2/0)

except exception as a:

result["msg"] = "除數不能為0"

result["code"] = 403

result["data"] = [,]

finally:

return json.dumps(result)

if __name__ == '__main__':

print(test())

'''module 和目錄的區別,看是否有__init__.py檔案

'''from 第八次課.py import test

test()

#常用模組

from datetime import datetime

print(datetime.now())

print(datetime.now().year)

print(datetime.now().month)

print(datetime.now().day)

print(datetime.now().hour)

print(datetime.now().minute)

print(datetime.now().second)

print(datetime.now().microsecond)

print(type(datetime.now().strftime("%y-%m-%d")))  #時間轉換為字串

#srt from time

print(type(datetime.now()))

a = datetime.now().strptime("2018-04-22","%y-%m-%d")

print(type(a))

print(a)

nowtime = datetime.now()

nowtime += timedelta(days=-365)   #列印出365天前的日期   +代表之後  "weeks="  "hours=" 

print(nowtime)

import time

time.sleep(10)

print("111")

print(time.time())  #時間戳

#時間戳就是從1970-01-01開始到現在的秒數

print(time.ctime()) #linux裡的ctime

print(time.localtime())

#列印出time.struct_time(tm_year=2018, tm_mon=4, tm_mday=22, tm_hour=21, tm_min=49, tm_sec=24, tm_wday=6, tm_yday=112, tm_isdst=0)

time.mktime() #跟localtime相反

time.asctime() 把乙個表示時間的元組或者struct_time表示為這種形式:'sun jun 20 23:21:05 2017'如果沒有引數,將會將time.localtime()作為引數傳入

'''內建模組

linux才有的commands模組

commands.getoutput(cmd)

返回結果為cmd

例如:a = commands.getstatusoutput("ifconfig")

返回status  0為失敗

getputput  只返回結果

import subprocess

result = subprocess.popen("ipconfig")

print(result)

'''import subprocess

result = subprocess.popen("ipconfig")

subprocess.getoutput("ipconfig")

print(result)

'''call() 呼叫系統命令

subprocess.check_call["ls","-l"]

'''subprocess.popen(['dir'])

''''''

安卓第十次課

android 系統竟然是內建了資料庫的,sqlite 是散輕量級的關係型資料庫,它的運算速度非常快,古用資源很少,通常只需要幾百kb的記憶體就足夠了,因而特別適合在移動裝置上用。sqlite不僅支援標準的sol語法,還遵循了資料庫acid事務,所以只要你以前使用過其他的關係型資料庫,就可以很快地上...

第十次練習

5位運動員參加了10公尺臺跳水比賽,有人讓他們 比賽結果 a選手說 b第二,我第三 b選手說 我第二,e第四 c選手說 我第一,d第二 d選手說 c最後,我第三 e選手說 我第四,a第一 比賽結束後,每位選手都說對了一半,請程式設計確定比賽的名次。include include 查重函式 int c...

第十次作業

linux網路服務 osi七層模型 物理層 傳輸介質,組網 資料鏈路層 mac位址定址,資料成幀,資料檢測,重發apr 網路層 將網路位址轉化為實體地址,網路位址定址,路由 ip協議 傳輸層 提供端對端的資料交換,連線,埠 會話層 提供點對點的連線 表示層 資料格式化 應用層 應用程式,服務 tcp...