-
s = '這是一句中英文混合的Python字符串:Hello World!'
print(s)查看全部 -
template2?=?'Hello?{2},?Hello?{3},?Hello?{1},?Hello?{0}.'
result2?=?template2.format('World',?'China',?'Beijing',?'imooc')
print(result2)查看全部 -
運行Python程序有兩種方式,第一種是直接通過命令行編寫代碼運行,第二種是通過編輯器編寫代碼運行。
查看全部 -
#1
template='life is short,you need {}'
python=python
print(template.format(python))
查看全部 -
a="hello "
b="world"
print(a,b)查看全部 -
for item in L:
? ?if item in S:
? ? ? ?S.remove(item)
? ?else:
? ? ? ?S.add(item)查看全部 -
name_set=set(names)
查看全部 -
value可以是任意類型的元素,可以是list、tuple等,假如Mimi近兩次成績分別是72,73,Dodo近兩次的成績分別是88,90,則可以使用賦值語句往dict中添加list元素。
查看全部 -
布爾運算只有兩種結果 True,False 用and,or,not運算 對應與,或,非運算,真(True),假(False)
與運算:兩真為真,一假為假 只有兩個布爾值都為 True 時,計算結果才為 True。兩真為真,一假為假
True and True # ==> True
True and False # ==> False
False and True # ==> False
False and False # ==> False或運算:一真為真,兩假為假 只要有一個布爾值為 True,計算結果就是 True。兩假為假,一真為真
True or True # ==> True
True or False # ==> True
False or True # ==> True
False or False # ==> False非運算:真對應假,假對應真 把True變為False,或者把False變為True 非真即假,非假即真
not True # ==> False
not False # ==> True
需要注意的是,not計算的優先級是高于and和or的。查看全部 -
四則運算 浮點數可以表達整數的結果,但是整數不能表達浮點數的結果。
取模運算 使用百分號%表示取模。使用取模運算,可以判斷一個數是否為偶數,當一個數對2取模結果為0時,則這個數為偶數,否則為奇數。
print(3 % 2) # ==> 1 因此3為奇數
print(33 % 2) # ==> 1 因此33為奇數
print(100 % 2) # ==> 0 因此100為偶數地板除 得到的結果會忽略純小數的部分,得到整數的部分,地板除使用//進行。
10//4 # ==> 2
10//2.5 # ==> 4.0
10//3 # ==> 3小數點位數 round()函數 round(變量,位數)
round的調用方式,使用兩個參數,第一個是需要保留小數點位數的數值,第二個是保留的位數。
查看全部 -
# Enter a code
str=r'''"To be, or not to be": that is the question.'''+'\n'+r'''Whether it's nobler in the mind to suffer.''';
print(str);
查看全部 -
L = ['Alice', 66, 'Bob', True, 'False', 100]
n = 0
for item in L :
? ? n = n + 1
? ? if n%2 == 0 :
? ? ? ? continue
? ? print(item)
查看全部 -
# Enter a code
L = ['Chinese', 92, 'Math', 75, 'English', 99]
print(L)
查看全部 -
cmp()函數,可以比較兩個數的大小,
查看全部 -
s1 = 'ABC'
s2 = '123'
s3 = 'xyz'
for i in s1:
? ?for n in s2:
? ? ? ?for m in s3:
? ? ? ? ? ?print(i + n + m)查看全部
舉報