python基礎知識
python
一:python簡單介紹web
a.python基礎算法
-基礎練習編程
-基礎數據類型設計模式
-函數api
-面向duix網絡
b.網絡編程ide
c.web編程函數
d.設計模式與算法工具
介紹:Python是一種解釋型、面向對象、動態數據類型的高級程序設計語言。
學習python課程,從基礎知識到web項目開發以及爬蟲系統項目代碼開發實踐課程記錄。
二:本次python開發版本3.0+ ,python安裝不進行演示,使用開發工具pycharm
三:執行python
變量:
n1 = input("輸入變量名") print(n1)
#變量構成:
字母
數字
下劃線
不能使用數字開頭,不能使用python關鍵字
字符串:
name = "hello"
運算符:
+ - * / % **
in not in 判斷字符是否包含在其中
n1=9 n2=2 n3=n1+n2 n3=n1-n2 n3=n1*n2 n3=n1/n2 n3=n1%n2 n3=n1**n2
循環:
死循環: while 1==1: print("ok") 循環遍歷0到9 count=0 while count<10: print(ok) count += 1 一、輸出1-100內的因此偶數 count=1 while count<=100: if(count%2!=0): pass else : print(count) count = count+1 二、求1-2+3-4+5...99的全部數的和 count=1 sum1=0 sum2=0 while count<100: if(count%2!=0): sum1=count+sum1 else : sum2=count+sum2 count = count+1 print(sum1-sum2)
判斷:
name = xixihaha if "xi" not in name: print("ok") else : print("error")
布爾值: 真True 假 False
邏輯運算 : not and or
數據類型:
str:
test="alex" test.capitalize() 首字母大寫,其餘小寫 test.casefold() 所有小寫(牛) test.lower() 所有小寫 test.upper() 所有大寫 test.swapcase() 大小寫轉換 test.islower() 是否全是小寫 test.isupper() 是否全是大寫 test.center(20,"*")設置寬度,並將內容居中,20代指總長度,* 空白位置填充(一個字符) test.count("a") 計算字符中出現個數從0開始 test.count("a",5,7) 從第5位開始,到第7位結束 test.endswith("a") 以什麼結尾,返回bool值 test.startswith('x')以什麼開始,返回bool值 test.find("ex") 從開始到最後,找到第一個後獲取其位置,未找到返回-1 test.find("ex",3,7) 從第3位開始,到底7位結束 格式化,將一個字符串的佔位符替換爲指定的值 test='i am {name},age {age}' test.format(name='alex',age='20') 格式化,將一個字符串的佔位符替換爲指定的值 test='i am {0},age {1}' test.format('alex',10) 格式化,傳入的值{"name":"xie","age":23} test='i am {name},age {age}' test.format('alex',10) test.format_map({"name":"xie","age":23}) 識別\t ,\n 等標籤 test="1234567\t89" test.expandtabs(2)空白位置數 join插入,將字符串的每個元素安裝指定分隔進行拼接 test="我就是我不同的煙火" t='' t.join(test) #等同於 "".join(test) t='_s' test.join(t) 分隔 test="testegesjuisfsgwsfhwrweydasgstee" test.partition("s")#只能把字符串分隔爲三份 test.rpartition() test="testegesjuisfsgwsfhwrweydasgstee" test.split("s")#所有找到進行分隔,沒法保留分隔符「s」 test.split("s",1) test.rsplit() test="alex" #索引,下標,獲取字符串中的某一個字符 test[2] test[0:2]# 0<= val <2 test[0:-1] #切片 字符串一旦建立,不能夠修改 一旦修改或者拼接,都會形成從新生成字符串 #替換 test="alexalexalex" test.replace("ex","bbb")#所有替換 test.replace("ex","bbb",1)#替換第一個 test.replace("ex","bbb",2)#替換前兩個