Python練習 容器 字串

2021-10-08 17:57:04 字數 820 閱讀 3115

容器

「」"如果在原有記憶體上修改資料,可能影響其他物件的記憶體

1、在終端中獲取乙個字串,迴圈列印每個字元的編碼值

char=

input

("請輸入字串;"

)for item in

(char)

: a=

ord(item)

print

(a)

2、在終端中反覆錄入乙個編碼值,然後列印字串,(如果錄入空字串,則退出程式)

q=

int(

input

("請輸入編碼值:"))

for item in

(str

(q )):

#不能用for迴圈

char =

chr(

int(item)

)print

(char)

while

true

: q =

int(

input

("請輸入編碼值:"))

if q =="":

break

print

(chr

(q))

#字串格式化

a=

int(

input

("請輸入斤"))

b=int

(input

("請輸入兩"))

print

("%d斤%d兩"

%(a,b)

)

Python字串練習

python mystr hello world and dgjfkhgj title 返回乙個首字母大寫的字串 print mystr.title capitalize 返回第乙個首字母大寫的字串 print mystr.capitalize upper 返回全部大寫 print mystr.up...

python 字串練習

name gouguoq 移除name變數對應值的兩邊的空格,並輸出移除後的內容 print name.strip 判斷name變數對應的值是否以 go 開頭,並輸出結果 print name.startswith go 判斷name變數對應的值是否以 q 結尾,並輸出結果 print name.e...

Python字串練習

取得校園新聞的編號 方法一 s s 14 5 方法二 s s.rstrip html 9 方法三 s s.rstrip html split 1 截圖 產生python文件的 addr1 addr2 html addr addr1 addr2 print addr 產生校園新聞的一系列新聞頁 for...