标签:
1.字符编码
python2.7中
#_*_coding:utf-8_*_ print ‘你好‘
python3.5中不需要为讨厌的字符编码而烦恼
print(‘你好‘)
2.print
python3.5中需要加()
3.某些库改名
old name new name
_winreg winreg
ConfigParser configparser
copy_reg copyreg
Queue queue
SocketServer socketserver
markupbase _markupbase
repr reprlib
test.test_support test.support
|
1
2
3
4
5
6
7
|
1、下载安装包 https://www.python.org/downloads/2、安装 默认安装路径:C:\python273、配置环境变量 【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【Python安装目录追加到变值值中,用 ; 分割】 如:原来的值;C:\python27,切记前面有分号 |
在linux 下创建一个文件叫hello.py,并输入
#!/usr/bin/env python
print("hello world")
如此一来,执行: ./hello.py 即可。
ps:执行前需给予 hello.py 执行权限,chmod 755 hello.py
注释:
当行注视:# 被注释内容
多行注释:""" 被注释内容 """
#!/usr/bin/env python
#_*_coding:utf-8_*_#name = raw_input("What is your name?") #only on python 2.xname = input("What is your name?")#3.5print("Hello " + name )#!/usr/bin/env python
# -*- coding: utf-8 -*- import getpass # 将用户输入的内容赋值给 name 变量pwd = getpass.getpass("请输入密码:") # 打印输入的内容print(pwd)(1)sys
import sysprint(sys.argv) $ python test.py helo world [‘test.py‘, ‘helo‘, ‘world‘] #把执行脚本时传递的参数获取到了(2)os
import os
os.system("df -h") #调用系统命令
(3)tab补全模块
1 #!/usr/bin/env python 2 # python startup file 3 import sys 4 import readline 5 import rlcompleter 6 import atexit 7 import os 8 # tab completion 9 readline.parse_and_bind(‘tab: complete‘) 10 # history file 11 histfile = os.path.join(os.environ[‘HOME‘], ‘.pythonhistory‘) 12 try: 13 readline.read_history_file(histfile) 14 except IOError: 15 pass 16 atexit.register(readline.write_history_file, histfile) 17 del os, histfile, readline, rlcompleter
标签:
原文地址:http://www.cnblogs.com/hongpeng/p/5832764.html