python基礎實踐(五)

來源:互聯網
上載者:User

標籤: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基礎實踐(五)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.