class LoopError(Exception):pass rs = '' try: for i in range(1, 3): print i rs = 'one ' if i == 1: for j in range(12, 22): print j if j == 13: rs = 'bbs' raise LoopError except LoopError: #跳出,遇到LoopError print rs print 'good' else: #循环完毕,没抛出LoopError…
上一篇:Python For嵌套循环 图形打印X型 nested loop - 练习题 上一篇留的Python For嵌套循环 图形打印X型练习题的答案. 由于网上很多嵌套循环都是C++语言写的,用Python也来尝试下吧. 输出结果: O.....O .O...O. ..O.O.. ...O... ..O.O.. .O...O. O.....O Python3.6代码: for line in range(0,3): for star in range(line): print("."…
使用python原生的方法实现发送email import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.base import MIMEBase from email.utils import COMMASPACE from email import encoders import os # 发送账号信息 sender = '…