python學習記錄1 基礎知識

2021-08-16 23:41:24 字數 2227 閱讀 2890

1.在python中使用變數時,需要遵守一些規則和指南。違反這些規則將引發錯誤,而指南旨在讓你編寫的**更容易閱讀和理解。請務必牢記下述有關變數的規則。

1.1變數名只能包含字母、數字和下劃線。變數名可以字母或下劃線打頭,但不能以數字打頭,例如,可將變數命名為message_1,但不能將其命名為1_message。

1.2變數名不能包含空格,但可使用下劃線來分隔其中的單詞。例如,變數名greeting_message可行,但變數名greeting message會引發錯誤。

1.3不要將python關鍵字和函式名用作變數名,即不要使用python保留用於特殊用途的單詞,如print (請參見附錄a.4)。

1.4變數名應既簡短又具有描述性。例如,name比n好,student_name比s_n好,name_length比length_of_persons_name好。

1.5慎用小寫字母l和大寫字母o,因為它們可能被人錯看成數字1和0。

1.6要建立良好的變數名,需要經過一定的實踐,在程式複雜而有趣時尤其如此。隨著你編寫的程式越來越多,並開始閱讀別人編寫的**,將越來越善於建立有意義的變數名。

注意  就目前而言,應使用小寫的python變數名。在變數名中使用大寫字母雖然不會導致錯誤,但避免使用大寫字母是個不錯的主意。

2.字串

2.1在python中,用引號括起的都是字串,其中的引號可以是單引號,也可以是雙引號(正確使用單雙引號,避免語法錯誤)

2.2 方法

2.2

.1string.title() 字串中的每個單詞首字母大寫

2.2.2string.upper() 字串中的所有字母大寫

2.2.3string.lower() 字串中的所有字母小寫

2.2.4string.rstrip() 刪除字串末尾的空白

2.2.5string.lstrip() 刪除字串起始的空白

2.2.6string.strip() 刪除字串首尾兩端的空白

3.數字計算

3.1基本運算

+ - * /

** a ** n //a的n次方

支援混合運算

與字串連線時,使用str()轉換為字串

3.2注意運算中整型和浮點型資料的轉換

4.注釋(#)

5.python之禪

the zen of python, by tim peters

beautiful is better than ugly.

explicit is better than implicit.

****** is better than complex.

complex is better than complicated.

flat is better than nested.

sparse is better than dense.

readability counts.

special cases aren't special enough to break the rules.

although practicality beats purity.

errors should never pass silently.

unless explicitly silenced.

in the face of ambiguity, refuse the temptation to guess.

there should be one-- and preferably only one --obvious way to do it.

although that way may not be obvious at

first unless you're dutch.

now is better than never.

although never is often better than *right* now.

if the implementation is hard to explain, it's a bad idea.

if the implementation is easy to explain, it may be a good idea.

namespaces are one honking great idea -- let's do more of those!

學習記錄 網路基礎知識(1)

1.網路的拓撲結構 匯流排結構,星形結構,環形結構,樹形結構,分布式結構。物理層,資料鏈路層,網路層,傳輸層,會話層,表示層,應用層。3.物理層互聯裝置 中繼器,集線器。4.資料鏈路層互聯裝置 網橋,交換機。5.網路層互聯裝置 路由器。6.應用層互聯裝置 閘道器。7.tcp ip協議是interne...

python學習筆記(1)基礎知識

python嚴格區分大小寫建議 變數名稱全部小寫,常量名稱全部大寫 python中的一切都是物件,變數是物件的引用 a jack 記憶體中的變數指向記憶體中的物件 字串是不可變型別 print self,args,sep end n file none del關鍵字,可刪除變數 函式 類等等 pyt...

python基礎知識1

學習python語言程式設計 嵩天,黃天宇,禮欣 補充內容 資料型別 例子整形 1 0,10,0xa,0o12,0b1010 浮點型1.27 1.25e9 1.25 10 9 1 2i 複數 字串 a sadf 列表 cat bat rat 1 2 3 元組 abc 1 2.1 字典布林代數 tru...