一:變量和簡單數(shù)據(jù)類型 1. 變量: 變量名只能包含字母、數(shù)字和下劃線。 變量名不能包含空格、Python關(guān)鍵字。 大小寫區(qū)分
message = "Hello Python world!"PRint(message)2. 字符串: 字符串中包含引號和撇號
print('I told my friend, "Python is my favorite language!"')print("The language 'Python' is named after Monty Python, not the snake.")print("One of Python's strengths is its diverse and supportive community.")以首字母大寫的方式顯示每個單詞
name = "ada lovelace"print(name.title())合并(拼接)字符串
first_name = "ada"last_name = "lovelace"full_name = first_name + " " + last_nameprint(full_name)使用制表符或換行符
print("/tPython")print("/nPython")刪除空白 刪除字符串末尾空白,可使用方法rstrip() 刪除字符串開頭的空白,使用lstrip() 同時剔除字符串兩端的空白,使用strip()
s1 = " message "print(s1)print(s1.rstrip())print(s1.lstrip())print(s1.strip())3. 數(shù)字 整數(shù) 可對整數(shù)執(zhí)行加(+ )減(- )乘(* )除(/ )乘方(**)運(yùn)算
浮點數(shù) Python將帶小數(shù)點的數(shù)字都稱為浮點數(shù)
整數(shù)用作字符串 調(diào)用函數(shù)str()
age = 23message = "Happy " + str(age) + "rd Birthday!"print(message)4. 注釋 注釋用井號(# )標(biāo)識
新聞熱點
疑難解答