標籤:print pos 執行 結構 next list mon class div
# -*- coding:utf-8 -*-
# Author:sweeping-monk
# -*-巨集指令清單-*-
Traverse_the_list = [‘guanfu‘,‘xiaole‘,‘fangdong‘,‘rourou‘]
for name in Traverse_the_list: #通過for迴圈將列表中的元素都一個一個的列印出來。
print(name)
#magicians = [‘alice‘,‘david‘,‘carolina‘] #練習for迴圈。
#for magician in magicians:
# print(magician.title() + ",that was a great trick!") #這一行必須縮排,否則報錯。
# print("I can‘t wait to see your next trick, " + magician.title() + ".\n") #要想讓for迴圈執行,就必須在for迴圈後面縮排。
magicians = [‘alice‘,‘david‘,‘carolina‘] #練習for迴圈。
for magician in magicians:
print(magician.title() + ",that was a great trick!")
print("I can‘t wait to see your next trick, " + magician.title() + ".\n") #這是沒縮排後的效果。
Chicken_soup = ‘‘‘
python根據縮排來判斷程式碼與前一個程式碼的關係,縮排讓代碼整潔而結構清晰。
‘‘‘
print(Chicken_soup)
Common_mistakes = "常見的縮排錯誤舉例:\n"
print(Common_mistakes)
#magicians = [‘alice‘,‘david‘,‘carolina‘]
#for magician in magicians:
#print(magician.title() + ",that was a great trick!") #應縮排卻沒縮排,python會提醒你。
magicians = [‘alice‘,‘david‘,‘carolina‘]
for magician in magicians:
print(magician.title() + ",that was a great trick!")
print("I can‘t wait to see your next trick, " + magician.title() + ".\n") #這一條沒有縮排,因此它只能迴圈結束後執行一次。
#這是一個邏輯錯誤。從文法上看是合法的。
#msg = "lao si ji"
# print(msg) #沒必要的縮排。
#Traverse_the_list = [‘guanfu‘,‘xiaole‘,‘fangdong‘,‘rourou‘]
#for name in Traverse_the_list #for語句後面的冒號告訴python,下一話是迴圈的第一行。這裡漏掉了冒號導致語法錯誤。
# print(name)
python基礎實踐(五)