Python學習之路-Linux下的HelloWord
阿新 • • 發佈:2018-02-19
程序 word 一行 pan als 完全 重復 helloword 字符串
字符編碼
- ASCII
- gb2301
- GBK
- gb18030
- Unicode 2bytes(2個字節)
- utf-8 英語:1byte(1個字節)漢語:3bytes(3個字節)
語言基礎
- getpass模塊:隱藏輸入字符(終端可用)
- 三引號(”“”“”“):作用一:多行註釋,作用二:多行文本
- 循環
- 判斷
- 格式化輸出
- break結束本層循環,continue跳出本層循環進入下一層
- 默認編碼:utf-8
while 循環 參考網址:http://www.runoob.com/python/python-for-loop.html
Python for循環可以遍歷任何序列的項目,如一個列表或者一個字符串。
語法:
for循環的語法格式如下:
#Python 編程中 while 語句用於循環執行程序,即在某條件下,循環執行某段程序,以處理需要重復處理的相同任務。其基本形式為:
while 判斷條件:
執行語句...
- for 循環
#Python for循環可以遍歷任何序列的項目,如一個列表或者一個字符串。 #語法: #for循環的語法格式如下: for i in range(1,5): print(i)
- break
#Python break語句,就像在C語言中,打破了最小封閉for或while循環。 #break語句用來終止循環語句,即循環條件沒有False條件或者序列還沒被完全遞歸完,也會 #停止執行循環語句。#break語句用在while和for循環中。 #如果您使用嵌套循環,break語句將停止執行最深層的循環,並開始執行下一行代碼。 #語句語法: __author__ = "KuanKuan" for i in "Python": print("當前字母:",i) #輸出結果: #當前字母: P #當前字母: y #當前字母: t #當前字母: h #當前字母: o #當前字母: n i = 10 while i > 0: print("當前變量值:",i) #打印當前變量值 i = i-1 if i == 5: #當i的值等於5時推出循環 breakprint("拜拜") """ 輸出結果: 當前變量值: 10 當前變量值: 9 當前變量值: 8 當前變量值: 7 當前變量值: 6
拜拜
- continue
""" Python continue 語句跳出本次循環,而break跳出整個循環。 continue 語句用來告訴Python跳過當前循環的剩余語句,然後繼續進行下一輪循環。 continue語句用在while和for循環中。 語句語法: """ __author__ = "KuanKuan" for i in "Python": if i == "o": continue print("當前字母:",i) i = 10 while i > 0: print("當前變量值:",i) #打印當前變量值 i = i-1 if i == 5: #當i的值等於5時推出循環 break print("拜拜") """ 當前字母: P 當前字母: y 當前字母: t 當前字母: h 當前字母: n 當前變量值: 10 當前變量值: 9 當前變量值: 8 當前變量值: 7 當前變量值: 6 拜拜 """
Python學習之路-Linux下的HelloWord