Published 7月 30, 2018 by with 0 comment

習題6 - 字符串和文本



用Notepad++打下列的程式碼,
另存為ex6.py.
type_of_people = 10
x = f"There are {type_of_people} types of people."

binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}."

print (x)
print (y)

print (f"I said: {x}")
print (f"I also said: '{y}'")

hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"

print (joke_evaluation.format (hilarious))

w = "This is the left side of ..."
e = "a string with a right side."

print (w + e)

然後用Windows的cmd, 執行python打開它.
C:\Windows\System32>cd C:\Users\Peter\Desktop\Python\LP3THW

C:\Users\Peter\Desktop\Python\LP3THW>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.

C:\Users\Peter\Desktop\Python\LP3THW>

完成
這次練習主要是學習把一個字串放進另外一個字串.
Line 1 - 2, 主要是學習將一個字串放進去
Line 4 - 5, 主要是學習將兩個字串分別放在兩個地方
Line 14 - 15, 主要是學習將一個字串分別再放進另外一個字串
Line 19, 我用另外一種方式表達出來跟上面相同的結果.
type_of_people = 10
x = f"There are {type_of_people} types of people."

binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}."

print (x)
print (y)

print (f"I said: {x}")
print (f"I also said: '{y}'")

hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"

print (joke_evaluation.format (hilarious))

TEST = f"{joke_evaluation.format (hilarious)}"
print (f"{TEST}")

w = "This is the left side of ..."
e = "a string with a right side."

print (w + e)

結果,
C:\Users\Peter\Desktop\Python\LP3THW>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
Isn't that joke so funny?! False
This is the left side of ...a string with a right side.

C:\Users\Peter\Desktop\Python\LP3THW>

Line 6 & 7, 是相同的結果. 這是我我用另外一種方式表達.


最初發表 / 最後更新: 2018.07.30 / 2018.07.30

0 comments:

張貼留言