2022年 11月 7日

Python-语法(来源于w3c内容总结的)

前言——可以直接在命令行中 编写python,创建python时扩展名格式为.py,并且可以在命令行中运行。

python缩进

缩进指的是代码行开头的空格。

在其他编程语言中,代码缩进仅出于可读性的考虑,而 Python 中的缩进非常重要。

Python 使用缩进来指示代码块。

例:

正确

if 3 > 2:
  print("Three is greater than two!")

if 3 > 2:

print(“Three is greater than two!”)

 空格取决于自己,但是最少要有一个空格。Python 使用缩进来指示代码块。

if 3 > 2:
 print("Five is greater than two!") 
        print("Five is greater than two!")