Python學習筆記(十)Python運算子

2022-08-26 04:42:08 字數 1008 閱讀 2699

1.基本運算

+   -   *   /   %取餘   //取商  **冪

2.其他運算

字元相關

成員操作運算子

判斷某個東西是否在某個東西裡面

in  not in

子串行(子字串)必須連續才正確,非連續判斷都是error

#!/usr/bin/env python

#-*-coding:utf8-*-

name="鄭建文"

if "正" in name:

print("ok")

else:

print("error")

3. 布林值

布林值:true真 false假

if true:

if 1==1:

v="文" not in name

if v :

print(111)

4. 比較運算子

==>

<

>=

<=

!=不等於

<>不等於

not 非

注意:整體注釋,選中後按住ctrl+?

5. 邏輯運算子

andor

user="alex"

pwd="123"

user=="alex" and pwd=="123" or 1==1 and pwd=="9962"

執行順序有括號先括號,無括號依次執行

true or ====>true

true and ====>繼續執行

false or ====>繼續執行

false and ====>false

6.賦值運算子

coun=coun+1===>coun+=1

coun=coun-1====>coun-=1

coun=coun*1====>coun*=1

coun=coun/1====>coun/=1

coun=coun//1====>coun//=1

Python學習筆記(十)

mylab 專案實戰 1 在templates中乙個index.html我需要引入當前資料夾中的另乙個網頁,我直接在index的 中引入 html無效 最後,我在這個專案的主目錄下的urls中進行設定,可行 2 在呼叫網頁的時候,進行views設定,就已經把處理函式給選定了 直接在views,用re...

python學習筆記十

字典遍歷 集合函式 copy僅拷貝物件本身,而不對中的子物件進行拷貝,故對子物件進行修改也會隨著修改。dict1 dict2 dict1 dict3 dict1.copy dict1 user root dict1 num remove 1 print dict1 print dict2 print...

Python學習筆記(十) Python文件

以mark lutz著的 python學習手冊 為教程,每天花1個小時左右時間學習,爭取兩周完成。寫在前面的話 2013 7 20 20 00 學習筆記 1,python以 開始 注釋。python也支援可自動附加在物件上的文件,而且可以在執行時檢視。這類注釋是寫成字串,放在模組檔案 函式 類語句的...