Python笔记一:基础语法

2017-06-14  本文已影响0人  林宥之

基于Python3.x。

一:HelloWorld

print("Hello World")

二:标识符

和Java无多大区别。

三:保留字

['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']```

# 四:注释

![注释.png](https://img.haomeiwen.com/i2954781/302493e4d53788d5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


# 五:缩进
> python使用缩进来表示代码块,不需要使用大括号{ }。
缩进的空格数是可变的,但是同一个代码块的语句必须包含相同的缩进空格数。

正确缩进例子
```python
if True:
    print("True")
else:
    print("False")

错误缩进例子,运行会导致报错。

if True:
    print("True")
else:
    print("False")
  print("False")  # 缩进不正确 , IndentationError: unindent does not match any outer indentation level

六:数据类型

变量可以有不同类型的值,称之为数据类型。基本数据类型数字字符串。除了基本类型,还有其他自己定义的类,跟Java相似。

七:导入模块

在 python 用 import 或者 from...import 来导入相应的模块。

上一篇 下一篇

猜你喜欢

热点阅读