Time of Update: 2018-07-24
#! /usr/bin/python# -*- coding:utf-8 -*-"""an interesting topic Fibonacci sequence"""#the method we know how to solve this issue ----recursiondef fib(n): if n ==1 or n ==2 : return 1 else: return
Time of Update: 2018-07-24
屬性函數(@property) 在對象中兩個很重要的元素就是屬性和方法,在調用的時候兩者是有區別的。 class People: def __init__(self,first_name,last_name): self.first_name = first_name self.last_name = last_name def get_first_name(self): return self.first_namea =
Time of Update: 2018-07-24
1. 切片 Slice slice操作符: eg. L[0:3] , 取索引0,1,2的元素,不包括3。L[-1]取倒數第一個元素。L[:10:2]取前十個元素,每兩個取一次。 可以對list , tuple , str 進行slice操作。 2. 迭代 迭代使用 for...in...實現,只要對象是可迭代的,都可以使用迭代形式。isinstance(obj, Iterable) 注意:dict不是按照順序儲存的,所以dict迭代出的順序很可能不一樣。
Time of Update: 2018-07-24
判斷類型 在Python中我們可以使用type進行類型的判斷 #我們想看一個對象的的類型可以這樣class A: passa = A()type(a) == A #True#type(obj) 會返回建立a的類型 建立對象 #這個簡單,因為type會返回對象的類型,我們可以通過返回的類型建立對象type(a)()#如果建構函式有參數則應傳遞相應參數#上述語句可以分解為A = type(a)A() 建立類
Time of Update: 2018-07-24
#ecoding=utf-8import mathimport reimport csvdef fileREAD(fileURL,access): "傳入檔案路徑,返回隱藏檔內容的二維列表" localArray = [] # 建立一個列表用於隱藏檔內容 csvfile = file(fileURL, access) reader = csv.reader(csvfile) for line in reader:
Time of Update: 2018-07-24
keys = {"status":True, 'name':'aaa'}def fun1(keys): print 'fun1' print "keys:", keys print "keys address", id(keys) keys['status'] = Falsedef fun2(keys): print 'fun2' print "keys:", keys
Time of Update: 2018-07-24
調用Google 翻譯API進行翻譯 #!/usr/bin/python#coding: UTF-8import sys reload(sys) sys.setdefaultencoding('utf8') from xml.etree import ElementTree as ET #引入解析xml檔案的模組import re import urllib,urllib2 #引入接入網路介面API的模組from socket import error as
Time of Update: 2018-07-24
1.math模組 >>> dir(math) ['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial',
Time of Update: 2018-07-24
# -*- coding:utf-8 -*-import sysimport osclass test_class(): def hello(self): print(sys._getframe().f_code.co_name)def hello_world(): print('hello_world!') print(sys._getframe().f_code.co_name)if __name__ == '__main__': ttt = test_
Time of Update: 2018-07-24
Mac下安裝python以及jupyter notebook python安裝(anaconda) Mac內建python2版本的python,需要裝的一般都是3版本,anaconda是python的一種版本,anaconda2對應python2版本,anaconda3.6對於python3版本,只需官網下載https://www.continuum.io/downloads/相應版本即可。 下載之後可以預設安裝,直接安裝完成。 安裝完成後,進行如下操作,並啟用。此後用conda
Time of Update: 2018-07-24
有時候,我們在用firepath(不會的請點這裡)查看元素的XPath資訊,發現沒有可以用來定位的id資訊,這個時候我們就需要考慮用其他的可用的來定位元素。本文介紹如何通過元素節點中class name的值來定位頁面元素。還是以百度首頁,搜尋輸入框定位舉例: XPath截圖 相關指令碼代碼如下: # coding=utf-8from selenium import webdriverdriver =
Time of Update: 2018-07-24
稍微總結一下,否則總是忘。 [python] view plaincopyprint? 1. x = 'abc' 2. def fetcher(obj, index): 3. return obj[index] 4.
Time of Update: 2018-07-24
From: http://blog.csdn.net/jlnuboy/article/details/5732196 PyMOTW: json 模組: json 目的: JavaScript對象格式序列器 python版本: 2.6 json模組提供了一個類似於pickle中用於轉換記憶體中python對象為一個序列表示形式(“JavaScript Object Notation”)的API介面. 但和pickle不同的是,
Time of Update: 2018-07-25
標籤:返回 size 函數 dem pytho 函數調用 產生 print span 一、可迭代對象與迭代器 1.可以使用for迴圈的對象就是可迭代對象,例如list,tuple,dict,字
Time of Update: 2018-07-24
標籤:python函數 bsp 導致 階乘 其他 遞迴函式 棧溢出 學習python 邏輯 #
Time of Update: 2018-07-24
標籤:img 就是 常用 sed 資料 int code 學習 問題 1.函數的定義 def func():2.函數的調用 func()3.函數的傳回值#1.沒有傳回值#
Time of Update: 2018-07-25
標籤:port == 執行 代碼執行 waitkey span show lse python 基於SSVEP的BCI系統需要刺激介面,在PC端用python(主要OpenCV)實現,以下為代碼
Time of Update: 2018-07-24
標籤:參考資料 分離 3.0 @class 設計 ret eth 面向 port 寫在前面的話"""讀書的時候上過《設計模式》這一門課,當時使用的教材是程傑老師的《
Time of Update: 2018-07-25
標籤:指令 安全執行緒 安全 一個 狀態 網路 多核 time 睡眠狀態 Python的全域解譯器鎖GIL用於保護python解譯器,使得任意時刻,只有一個線程在解譯器中運行。從而保證安全執行緒
Time of Update: 2018-07-24
標籤:bsp spl path lin turn inner map 執行 hit 在學習Flask之前我們先來回顧一下裝飾器的知識:1.簡單的裝飾器,index函數被當做參數直接傳入wrapp