python基础实践(五)

# -*- 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)
posted @ 2017-12-25 23:13  sweeping-monk  阅读(264)  评论(0编辑  收藏  举报