注释:
单行注释 #
多行注释''' '''
注意:当注释中有汉字时需要在python文件的第一行添加如下内容之一:#coding:gbk或#coding:utf-8或##-*- coding : gbk -*-
hello world python:
#coding:utf-8
'''
Created on 2014-6-6 @author: yzl
''' print '----------基础类型的操作----------'
i = 10
print i
i = i+10
print i
print i*2 if i==20:
print 'i==',i str = 'string '
print str*2 bool = True or False
print bool s='this is test string \
hello world python'
print s l='''thi is test string
test to print hello world python'''
print l print '---------控制语句---------' # wait user input
num = int(raw_input('Enter an integer :'))
if num<10:
print 'this number is < 10'
elif num>=10 and num<=100:
print 'this number is bettween 10 and 100'
else:
print 'yeah! the num is:',num
for j in range(1,num):
if j<5:
continue
if j>=10:
break
print 'for run :',j step = 0
while bool:
if num<100:
step = step +1
print 'case 1,step is:',step
if step > 10:
break
elif num>=100:
bool = False
print 'case 2 to stop while'
# 当bool为false时执行
else:
print 'go to else case'
运行结果:
----------基础类型的操作----------
10
20
40
i== 20
string string
True
this is test string hello world python
thi is test string
test to print hello world python
---------控制语句---------
Enter an integer :200
yeah! the num is: 200
for run : 5
for run : 6
for run : 7
for run : 8
for run : 9
case 2 to stop while
go to else case Enter an integer :30
this number is bettween 10 and 100
for run : 5
for run : 6
for run : 7
for run : 8
for run : 9
case 1,step is: 1
case 1,step is: 2
case 1,step is: 3
case 1,step is: 4
case 1,step is: 5
case 1,step is: 6
case 1,step is: 7
case 1,step is: 8
case 1,step is: 9
case 1,step is: 10
case 1,step is: 11