一 python學習之變數和字串

2021-09-22 10:28:48 字數 838 閱讀 5119

#請利用迴圈依次對list中的每個名字列印出hello, ***!:

l = ['bart', 'lisa', 'adam']

for i in l:

print('hello,'+i+'!')

字串之間的連線用「+」

2、列印輸出特殊符號的字串,如:d:\program files\microsoft office

#1、 #請利用迴圈依次對list中的每個名字列印出hello, ***!:

l = ['bart', 'lisa', 'adam']

for i in l:

print('hello,'+i+'!')

# #2、列印輸出特殊符號的字串,可以用'\',如需要轉義的字元多,前面加'r'

str=r'd:\program files\microsoft office'

#用'\'進行字元轉義

str='d:\\program files\\microsoft office'

print(str)

#輸出:

d:\program files\microsoft office

# d:\program files\microsoft office

#3、str='d:\program files'

str='d:\\program files'

print(str)

d:\program files

4、字串原樣輸出

str="""

i study python

"""輸出:

i study python

Python 學習筆記之變數

python中變數名規則與其它大多數高階語言一樣,都是受c語言影響。變數名一般由字元 數字 下劃線組成,python 變數名是 大小寫敏感的。python是動態型別語言,不需要預先宣告變數的型別。變數的型別和值在值在賦值那一刻決定。另外,python中,由於記憶體管理是由直譯器負責的,所以開發人員可...

python學習筆記之變數

python的字串列表有2種取值順序 從左到右索引預設0開始的,最大範圍是字串長度少1 從右到左索引預設 1開始的,最大範圍是字串開頭 如果你要實現從字串中獲取一段子字串的話,可以使用變數 頭下標 尾下標 就可以擷取相應的字串,其中下標是從 0 開始算起,可以是正數或負數,下標可以為空表示取到頭或尾...

python學習之變數型別

python的主要變數型別包括以下九種,可用type 函式檢視變數型別。num 1 num1 1 num2 num ty type num print ty print num print id num print id num1 print id num2 值得注意的是,從結果可以出這裡的num ...