首页 > 编程语言 > 详细

Python第一节

时间:2019-03-09 19:37:16      阅读:157      评论:0      收藏:0      [点我收藏+]

1、查看python保留字

>>> import keyword
>>> keyword.kwlist
[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]

2、python中注释

(1)单行注释以 # 开

(2)多行注释可以用多个 # 号,还有 ‘‘‘ 和 """:

3、行与缩进

python最具特色的就是使用缩进来表示代码块,不需要使用大括号 {} 。

缩进的空格数是可变的,但是同一个代码块的语句必须包含相同的缩进空格数

缩进不一致报:IndentationError: unindent does not match any outer indentation level

4、多行语句

Python 通常是一行写完一条语句,但如果语句很长,我们可以使用反斜杠(\)来实现多行语句

total = item_one +         item_two +         item_three

在 [], {}, 或 () 中的多行语句,不需要使用反斜杠(\)

total = [item_one, item_two, item_three,
        item_four, item_five]

5、数字(Number)类型

python中数字有四种类型:整数、布尔型、浮点数和复数。

  • int (整数), 如 1, 只有一种整数类型 int,表示为长整型,没有 python2 中的 Long。
  • bool (布尔), 如 True。
  • float (浮点数), 如 1.23、3E-2
  • complex (复数), 如 1 + 2j、 1.1 + 2.2j

 6、字符串(String)类型

  • python中单引号和双引号使用完全相同。
  • 使用三引号(‘‘‘或""")可以指定一个多行字符串。

 

 

 

 

Python第一节

原文:https://www.cnblogs.com/xinxin1994/p/10502516.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!