Python之路,Day2 Python基礎2

2022-09-04 02:12:09 字數 1501 閱讀 3069

本節內容

列表、元組操作

字串操作

字典操作

集合操作

檔案操作

字元編碼與轉碼 

列表是我們最以後最常用的資料型別之一,通過列表可以對資料實現最方便的儲存、修改等操作

定義列表

1names=['alex',"tenglan",'eric']

通過下標訪問列表中的元素,下標從0開始計數12

3456

78>>> names[0]

'alex'

>>> names[2]

'eric'

>>> names[-1]

'eric'

>>> names[-2]#還可以倒著取

'tenglan'

本節內容

列表、元組操作

字串操作

字典操作

集合操作

檔案操作

字元編碼與轉碼 

列表是我們最以後最常用的資料型別之一,通過列表可以對資料實現最方便的儲存、修改等操作

定義列表

1names=['alex',"tenglan",'eric']

通過下標訪問列表中的元素,下標從0開始計數12

3456

78>>> names[0]

'alex'

>>> names[2]

'eric'

>>> names[-1]

'eric'

>>> names[-2]#還可以倒著取

'tenglan'

Python學習之路Day2

message world print message 輸出結果為 world message hello world 輸出結果為 hello world print message 用引號 單 雙引號 括起來的都是字串 str1 this is a string str2 this is also...

day2 Python學習之路筆記(2)

1.1.我們寫好的.py檔案頭沒有加 coding utf 8 這樣的宣告,那麼在windows終端中呼叫python2直譯器執行時,檔案中的中文會顯示亂碼,為何?原來我們windows終端是以gbk編碼來讀的,而python2中不是預設的utf8的編碼格式。呼叫python3直譯器就沒問題,有中文...

python學習之路day2 迴圈

猜三次年齡,猜錯了三次程式退出 coding utf 8 age 56 count 0 while count 3 guess age int input 請輸入年齡 if guess age age print 你猜對了 break elif guess age age print 猜大了 els...