Python基礎學習 3

2021-08-27 11:04:09 字數 571 閱讀 5696

1.center居中字串,根據width兩側填充

#'_'代表空格

2.find查詢字串,返回索引(lfind\rfind 從首查\從尾查)

63.join合併序列

>>>a=['1','2','3','4'] #針對字元的操作

>>>b='+'

>>>b.join(a) #按閱讀順序 b join a

1+2+3+4

4.split拆分序列

['1','2','3','4']

5.strip刪除首尾指定字元,預設空格(lstrip\rstrip 刪首\刪尾)

>>>'*** sss * ttt * rrr!!! ***'.strip(' *!'

#可指定多個指定字元

'sss * ttt * rrr'

6.replace\translate替換字串(後者只能單個替換,需要做對映)

'this is an banana!'

>>>table=str.maketrans('ae')

'this is en epple!'

python基礎學習 3

建立列表的方式 1.使用中括號 2.呼叫內建函list lst hello world 666 使用中括號建立列表 lst2 list hello world 666 使用list內建函式建立列表1.獲取列表中指定元素的索引 lst hello world 666 hello print lst.i...

Python學習(一) python3基礎

主要參考廖雪峰的python教程 不斷的學習才能不斷發現好東西!富而不驕易,窮而不怨難 整數 int 浮點數 float 字串 str 布林值 bool 空值 nonetype 變數 常量 list 是一種有序的集合,可以隨時新增和刪除其中的元素 用索引來訪問list中每乙個位置的元素,記得索引是從...

Python學習總結3 Python基礎

一 介紹 python採用縮排方式 print absolute value of an integer a 100 if a 0 print a else print a 其中,為注釋。縮減用4個空格表示。其他每一行都是乙個語句,當語句以冒號 結尾時,縮排的語句視為 塊。二 資料型別 2.整數 包...