以做題的方式去攻克基本知識:
- a, b兩張表,a: abccd; b: acded ,使用sql語句查詢出a,b的accd。
由以上表中的數據可以看出accd屬於a,b的交集;
使用innersql語句查詢:
select * from B inner join B.name = A.name
驗證結果: accd - a = ‘abbbbccc’, 使用正則表達式匹配爲abccc不管由多少個b只允許出現一次。
所以使用re正則裏面的sub替換語法;
re.sub(r’b+’, ‘b’, a) - xpath 使用的是什麼庫?
lxml 庫 - py3,py2的區別;
print 函數的區別
input輸入輸出的區別
字符拆和字節的區別
編碼的區別; - Redis裏面內容的長
使用語句: len key_name - 多線程交互,訪問數據,如果訪問到了就不訪問了,怎麼去重?
創建一個已經訪問的數據列表,,如果訪問到了就不訪問了,並且需要加上互斥鎖。多線程訪問數據的時候,先去列表中進行查看,數據是否已經存在,存在不訪問,不存在則繼續訪問。 - mysql 怎麼限制ip的訪問.
對數據庫進行加密,用戶訪問需要通過用戶名密碼校驗通過之後才能訪問。、 - 帶參數的裝飾器:
函數的嵌套,內函數使用了外函數的局部變量,外函數返回了內函數的引用。
def new_fun(func):
def wrapperfunc(username,passwd):
if username == 'root' and passwd == '123456789':
print("驗證通過")
print("開始執行附加功能")
return func()
else:
print("用戶名密碼錯誤")
return
return wrapperfunc
@new_func # orgn = new_func(orgn)
def orgn():
print(“開始執行函數”)
orgn('root', passwd)
- python 主要內置的數據類型有那些?
str int float tuple list dict set - print(dir(‘a’))打印出什麼?
會打印出字符類型的所有內置方法
8. ['__add__','__class__','__contains__','__delattr__','__doc__','__eq__','__format__','__ge__','__getattribute__','__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
- 兩個列表找相同的元素和不同的元素。
AB中中相同的元素: print(set(A)&set(B))
AB中不同的元素: print(set(A)^set(B))
區別: 相同使用& 的符號; 不同使用 ^ 符號 - 反轉字符串;
new_str = old_str[::-1] - 交換AB兩個變量;
有很多種方法: 藉助第三方變量進行交換的;
簡單的一種: a,b = b,a - sql 語句: 用select語句輸出每個城市中心距離市中心的距離大於20km的酒店數量
select count (hotel) i from hotel_table where distance > 20 group by city - 給定一個有序列表,,請輸出要插入值k所在的索引位置。
def index(list, key):
if key < list[0]:
position = 0
elif key > list[-1]:
position = len(list)-1
else:
for index in range(list):
if key > list[index] and list[index] > key:
position = index