不區分單雙引號。
2.python的print自帶換行,結尾end預設為"\n"也可以改變。("hello world"
)hello world
('hello world'
)hello world
1.兩個乘法是指指數運算,普通除法中整數相除必得出浮點數,地板除結果是整數('hello world'
,end='')
('hello world'
)hello worldhello world
(ps:地板除為 //)
2.兩個字串可以利用加法進行「拼串」。print(3**2
)9print(3
/2)1.5
print(3
//2)1
(拼串只能是字串相拼)
3.字串和整數之間可以進行乘法,結果是重複幾遍字串('i'
+'love'
+'you'
)iloveyou
('a'+1
)typeerror: can only concatenate str
(not
"int"
) to str
1.#號單行注釋('a'*3
)aaa
#***x
2,三對引號(單或雙)多行注釋
『』『***』』』
1.if後面要有空格
2.空格後面是判斷主體
3,結尾要有:迴圈體要縮排else if可以縮排成elif,python程式設計中else if=elif
import random#匯入模組
suiji=random.randint(0,
100)
#生成0—100隨機數
#print(suiji)
import random#匯入模組
suiji=random.randint(0,
100)
#生成0—100隨機數
(suiji)
shuru=
input
('請輸入0-100的整數'
)shuru=
int(shuru)
#強制轉化
if shuru > suiji:
('大了'
)elif shuru < suiji:
('小了'
)else
('對了'
)
Python 入門筆記
前一段時間看了九天雁翎 http hi.csdn.net vagrxieeasy but powerful 總體感覺python的庫功能極其強大,這樣使得python 密度很高,用c 10行實現的內容,python可能不到3行就能實現了。當然這樣會損失一些效率,但是實現一些小的應用軟體不會有什麼問題...
python入門筆記( )
變數賦值 counter 0 miles 1000.0 name xumesang n 10 2.字串 str python str 0 p str 1 n str 2 pythonpython 3.列表,元組和字典 list 1,2,3,4 元素可變 tuple xumesang 23,101 元...
python入門筆記
1.編寫python記得縮排統一 2.連續輸出多個變數 print 橫座標是 d,縱座標是 d x,y 3.生成隨機數的方法 randint x,y 但在此前要匯入模組 from random import randint 注意。生成的數包括x和y,例如randint 1,10 可以生成1和10 4...