---
title: "Python Conditionals and Loops"
author: "fairy_xzc"
date: "2013-04-18T11:46:45Z"
tags: []
categories: ["编程语言"]
slug: "python-conditionals-and-loops"
draft: false
lastmod: "2013-04-18T11:46:45Z"
id: 1849365
url: "https://agilestyle.iteye.com/blog/1849365"
---

**print，import**

![](http://dl.iteye.com/upload/attachment/0083/3327/68d00a50-2eec-3bde-8a86-46335d7465bb.png)  
![](http://dl.iteye.com/upload/attachment/0083/3329/68c29fbd-6d02-3acb-8478-e2d6a1b0b48c.png)

**赋值**

![](http://dl.iteye.com/upload/attachment/0083/3331/78967b83-0d26-3b8f-9704-36b4d5081aac.png)  
![](http://dl.iteye.com/upload/attachment/0083/3333/3651acf7-3466-31cd-aecb-04c591370bf1.png)

**条件和条件语句：布尔值、bool函数、if、else、elif**

![](http://dl.iteye.com/upload/attachment/0083/3335/c053d8ee-a805-3bd6-b94e-6323a5b1bf1d.png)  
![](http://dl.iteye.com/upload/attachment/0083/3337/bc1b0dab-4d47-34e7-b3e6-49e7efb4f7b3.png)

**嵌套代码块、相等运算符==、同一性运算符is、成员资格运算符in、字符串和序列比较、布尔运算符、断言**

![](http://dl.iteye.com/upload/attachment/0083/3339/22c2e283-00ba-3bb9-b285-405f0140f367.png)  
![](http://dl.iteye.com/upload/attachment/0083/3341/f3220905-f2de-364c-a847-ecf7c003fc3f.png)  
![](http://dl.iteye.com/upload/attachment/0083/3343/3ac02f87-5a9f-3b30-b90f-f0847d040ca4.png)

**while、for、range**

![](http://dl.iteye.com/upload/attachment/0083/3345/e2565baa-14bb-3343-89c2-391dc5b2604a.png)  
![](http://dl.iteye.com/upload/attachment/0083/3351/6ad13494-4ba7-312e-b35a-8a6a459c9723.png)  
![](http://dl.iteye.com/upload/attachment/0083/3353/18601830-2f3b-3f22-8444-9bec6cc0b166.png)

**并行迭代、编号迭代、翻转和排序迭代**

![](http://dl.iteye.com/upload/attachment/0083/3355/64d0b85a-cca1-3380-8391-b25b3cbe8ef3.png)  
![](http://dl.iteye.com/upload/attachment/0083/3357/f9337c27-9a77-36d2-bc57-74a754f05f75.png)  
![](http://dl.iteye.com/upload/attachment/0083/3359/45a431fc-c6f5-3abc-8cd6-ffe78dfd96c3.png)

**break、continue、循环中else子句**

![](http://dl.iteye.com/upload/attachment/0083/3361/6a788d1d-43f7-32ec-8d58-b84f687b205a.png)  
 

**列表推导式(List Comprehension)**  
![](http://dl.iteye.com/upload/attachment/0083/3363/66dcb3ed-5e0e-3b13-ab3d-e160a6471428.png)  
 

**pass、del、exec、eval**

**pass语句什么都不做，可以作为占位符使用。**

**del语句用来删除变量，或者数据结构的一部分，但是不能用来删除值。**

**exec语句用于执行Python程序相同的方式来执行字符串。**

**内建的eval函数对写在字符串中的表达式进行计算并且返回结果。**

**![](http://dl.iteye.com/upload/attachment/0083/3365/645c85a3-8412-38c8-b852-c7ad4d446425.png)**  
**![](http://dl.iteye.com/upload/attachment/0083/3367/bfc0d1e1-74ff-3ebf-834e-960ab8b1121a.png)**  
**![](http://dl.iteye.com/upload/attachment/0083/3369/4736238e-670d-3faa-90fa-72ef83fc9810.png)**  
 

## summary

![](http://dl.iteye.com/upload/attachment/0083/3371/a1bf3031-9a60-397b-a7e2-49d0f4d16b7f.png)