day1
1.写个简单的Hello World程序
print
(
"Hello World!"
)
2.解释器的规范
#!/usr/bin/env python
# _*_coding:utf-8_*_
python 3.0后的版本不需要指定字符集了
3.变量定义
#格式
name = ‘Duan‘
NamePass = ‘Duan 123‘
#变量赋值
name = ‘Duan‘
NamePass = name
#NamePass的值其实Duan 无论name如何变化 因为是赋值不是继承
4.用户自定义输入
#字符串
name = input("pelease is xxxx")
#数字
name = int(input("pelease is xxxx"))
5.系统模块
如:
import os,sys
TABLE补全模块
#!/usr/bin/env python
# python startup file
import sys
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind(‘tab: complete‘)
# history file
histfile = os.path.join(os.environ[‘HOME‘], ‘.pythonhistory‘)
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
6.数据类型
字符串是 %s;整数 %d;浮点数%f
print
"i am %s "
%
name
7.if for 格式
if name == ‘xiaoneng‘:
print(‘xiaoxxxx‘)
elif name == ‘xiaohua‘:
print(‘xiaohuaxxxx‘)
else:
sys.exit
for i in range(10):
print $i