Introduction
-
It is an interpreted language: This means that there is no compilation in the development process. Similar to PHP and Perl languages.
-
Is an interactive language: This means that you can execute code directly after a Python prompt >>>.
-
Is an object-oriented language: This means that Python supports an object-oriented style or programming technique where code is encapsulated in an object.
-
A language for beginners: Python is a great language for junior programmers. It supports a wide range of application development, from simple word processing to WWW browsers to games.
Basic grammar
-
Comment
单行注释以#开头 多行注释用'''或""" Ctrl+\快速注释或取消
-
indentation
缩进的空格数是可变的,但是同一个代码块的语句必须包含相同的缩进空格数。 一般为4个空格或1个tab
-
Number type
数字有四种类型:整数、布尔型、浮点数和复数
-
String
python中单引号和双引号使用完全相同。 使用三引号('''或""")可以指定一个多行字符串。 反斜杠可以用来转义,使用r可以让反斜杠不发生转义。 如 r"this is a line with \n" 则\n会显示,并不是换行。 字符串可以用 + 运算符连接在一起,用 * 运算符重复。 Python 中的字符串有两种索引方式,从左往右以 0 开始,从右往左以 -1 开始。字符串的截取的语法格式如下:变量[头下标:尾下标:步长] Python中的字符串不能改变。 Python 没有单独的字符类型,一个字符就是长度为 1 的字符串。
-
print output
print 默认输出是换行的,如果要实现不换行需要在变量末尾加上 end="":
Import and from...import
Use import or from...import to import the corresponding modules in python. -
…