1. 程式人生 > >《“笨辦法”學python3》Ex 6

《“笨辦法”學python3》Ex 6

知識點:

文字中插入變數字串的方法

print(f".......{valuable}"}

w和e是兩個字串變數

可以用print(w+e)直接列印

程式:

types_of_people = 10
x = f"There are {types_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)

輸出:

PS C:\Users\xue weiruan\github> 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 C:\Users\xue weiruan\github>