Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2793279
  • 博文数量: 471
  • 博客积分: 7081
  • 博客等级: 少将
  • 技术积分: 5369
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-04 21:55
文章分类

全部博文(471)

文章存档

2014年(90)

2013年(69)

2012年(312)

分类: Python/Ruby

2012-02-25 11:08:17

事实上行首的空白是重要的。它称为缩进。在逻辑行首的空白(空格和制表符)用来决定逻辑行的缩进层次,从而用来决定语句的分组。这意味着同一层次的语句必须有相同的缩进。每一组这样的语句称为一个


  1. #!/usr/bin/python
  2. # Filename: if.py

  3. number = 23
  4. guess = int(raw_input('Enter an integer : '))

  5. if guess == number:
  6.     print 'Congratulations, you guessed it.' # New block starts here
  7.     print "(but you do not win any prizes!)" # New block ends here
  8. elif guess < number:
  9.     print 'No, it is a little higher than that' # Another block
  10.     # You can do whatever you want in a block ...
  11. else:
  12.     print 'No, it is a little lower than that'
  13.     # you must have guess > number to reach here

  14. print 'Done'
  15. # This last statement is always executed, after the if statement is executed
输出

$ python if.py
Enter an integer : 50
No, it is a little lower than that
Done
$ python if.py
Enter an integer : 22
No, it is a little higher than that
Done
$ python if.py
Enter an integer : 23
Congratulations, you guessed it.
(but you do not win any prizes!)

Done 


def someFunction():
    pass

pass语句在Python中表示一个空的语句块。

空格(行)使用 
  • 使用 4 个空格缩进。
  • 不要使用制表符。
  • 不要将制表符和空格混合使用。
  • IDEL和Emacs的Python的都支持 spaces模式。
  • 每个函数之间应该有一个空行。
  • 每一个 Class 之间应该有两个空行。
阅读(652) | 评论(0) | 转发(1) |
0

上一篇:Java Enum

下一篇:python 函数

给主人留下些什么吧!~~