Python學習筆記8 語法基礎

2021-09-13 19:29:08 字數 1850 閱讀 7638

s =

'i love hanxuexue'

print

(s)

i love hanxuexue
# 如果想表示出let's go來

# 1.可以使用巢狀引號,即外層使用雙引號

# 2.使用轉義字元

s ="let's go"

print

(s)# \' == '

ss =

'let\'s go'

print

(ss)

# \\ == \

sss =

"c:\\user"

print

(sss)

# 回車換行符

s1 =

'i love \r\nhanxuexue'

print

(s1)

let's go

let's go

c:\user

i love

hanxuexue

s =

"*** 您好,歡迎瀏覽我的csdn部落格"

s =

"i love %s"

# 下面列印,直接把%s作為字串的乙個內容列印出來了

print

(s)

i love %s
print

("i love %s"

%"hanxuexue"

)

i love hanxuexue
print

( s%

"hanxuexue"

)

i love hanxuexue
s =

"i am %d years old"

# 留意下面兩句話的區別和結果

print

(s)print

(s%18

)

i am %d years old

i am 18 years old

s =

"i am %s,i am %d years old"

print

(s)# 注意以下表達的出錯原因

# 如果字串中有多個佔位符,則必須有多個實際內容填入.或者乙個也不填

# print(s%'xiaoxiao')

print

(s%(

'xiaoxiao',18

))

i am %s,i am %d years old

i am xiaoxiao,i am 18 years old

s =

"i love {}"

.format

("hanxuexue"

)print

(s)s =

"yes, i am years old,i love and i am years old"

.format

("hanxuexue",18

)print

(s)

i love hanxuexue

yes, i am 18 years old,i love hanxuexue and i am 18 years old

Python學習筆記 語法基礎

注釋 n 換行符 續行符 連線同一行中的兩個語句 分隔 塊的頭和體 塊 縮排方式體現 一般賦值 增量賦值 不支援x x等自增 自減運算 多重賦值 x y z 1 多元賦值 x,y,z 1,2,3 交換 x,y y,x 關鍵字 專用下劃線識別符號 不用from module import 匯入 系統定...

Python學習筆記 基礎語法

1 python是一種解釋性語言,不需要進行編譯 2 python命令列引數 v 輸出python版本號 h 檢視幫助3 使用中文需要新增轉碼 檔案頭 在檔案開頭加入 coding utf 8 或者 coding utf 8 注意 python3.x原始碼檔案預設使用utf 8編碼,所以可以正常解析...

python 學習筆記 基礎語法

表示注釋 本行內容不會被執行 可以寫在開頭,或寫在某一 之後 import匯入乙個模組 當輸入乙個語句塊時 如if語句 需要分開成多行。為了說明下面的語句與上面的語句有關係,需要進行縮排,一般縮排為四個空格,稱為語法縮排。使用tab鍵進行縮排。資料型別 整數 int 8 浮點數flot 8.8 字串...