语法&错误笔记 day01

## 语法&错误笔记

### 语法

- python语法中,由上往下执行,一个流程中有一个条件满足后会停止执行下面的流程。

- 一定要注意各语名之前的层级缩进。

- if...elif...else

- print('')

```python
print("这个显示输出")
```

```python
# 三个引号,可以换行
content = '''床前明月光,
疑是地上霜。'''
print(content)
```

- while

```python
#循环嵌套
while True:
print('这是第一个循环')
while True:
print('这是第二个循环,需要下面加break,才能中止当前循环,进行第一个循环。')
break
break
```

```python
#打印1 2 3 4 5 6 8 9 10
count = 1
while count <= 10:
if count != 7:
print(count)
count = count + 1
print('结束')
```

```python
'''循环打印'''
count = 0
while count >= 0 and count <= 99:
count = count + 1
print(count)
#或者
count = 1
while count <= 100:
print(count)
count = count + 1
```

- break #中止当前循环

```python
#通过break实现1-10打印
count = 1
while True: #如果循环为真
print(count)
if count == 10:
break #如果count等于10则中止当前循环。
count = count + 1
print("结束")
```

### 错误笔记

1. python 中一定要注意语法之前的缩进。
2. 一个语法判断结束后面一定要加冒号。`:`
3. 判断 符号<= 中的等号不能写在<号的前面。
4. 注意大小写,如true 会报错,必须True.

猜你喜欢

转载自www.cnblogs.com/Dtime/p/10954272.html
今日推荐