笨辦法學Python 3 習題6

2021-10-02 21:15:23 字數 1326 閱讀 6580

【交作業啦】

ex6.py

# 建立了乙個名叫types_of_people的變數,並將其設為等於10

types_of_people =

10# 建立了乙個名叫x的變數,並將其設為f-string

x = f"there are types of people."

# 建立了乙個名叫binary的變數,並將其設為字串"binary"

binary =

"binary"

do_not =

"don't"

y = f"those who know and those who ."

# 列印變數

print

(x)print

(y)# 將x作為變數,放到f-string中列印

print

(f"i said: "

)print

(f"i also said: ''"

)hilarious =

false

joke_evaluation =

"isn't that joke so funny?! {}"

# 將hilarious作為變數,格式化列印已經建立的字串joke_evaluation

print

(joke_evaluation.

format

(hilarious)

)w =

"this is the left side of..."

e ="a string with a right side."

# 拼接兩個字串

print

(w + e)

執行結果

ps e:\lpthw> python .\ex6.py

there are 10 types of people.

those who know binary and those who don't.

i said: there are 10 types of people.

i also said: 'those who know binary and those who don't.'

isn't that joke so funny?! false

this is the left side of.

..a string with a right side.

ps e:\lpthw>

【學習心得】

1 標題是「字串和文字「,沒看到**提到了「文字」呢?

2 為什麼w和e用+連起來就可以生成乙個更長的字串呢?

《笨辦法學Python》 習題6

加分習題 系統 mac os 10.14 python 2.7.10 版本 笨辦法學python 第四版 x there are d types of people.10 binary binary do not don t y those who know s and those who s.bi...

《笨辦法學Python》 習題3

加分習題 系統 mac os 10.14 python 2.7.10 版本 笨辦法學python 第四版 print i will now count my chickens print hens 25 30 6.0 print roosters 100 25 3 4 print now i wil...

「笨辦法」學Python3 習題20 函式和檔案

目錄 函式與檔案 print後不自動換行 from sys import ar script,input file ar def print all f print f.read def rewind f f.seek 0 def print a line line count,f print li...