2016/09/02

1.Python安装(windows)

  1)官网下载: executable installer

  2)安装: python27 -> C/Python27

       python35 -> C/usr/administrator/Appdata/Local/Program/Python/Python35

  3)环境变量:ThisPC -> property -> advanced system settings -> environment variables -> Path -> Edit -> New : python35 file path (python.exe -> python3.ext)

2.Python安装(linux):还不会

3.'' ./ '' 执行,执行前需要给予hello.py执行权限:chmod 755 hello.py  /  chmod +x                          文件第一行:#!/usr/bin/env python

4.格式化字符串  %s  %d  %f

5.常用模块

  1)密文输入:import getpass

          password = getpass.getpass('password:')

  2)os:import os

       os.system('df -h')  #调用系统命令

       os.mkdir('your Dir')  #创建目录

       os.system('ls')  /  os.system('ls P*')  #显示文件

       cmd_res = os.popen('df -h').read()  #保存命令结果

  3)tab补全: tab.py一般放在 .../python2.7/dist-packages目录下

  4)sys:import sys

      print(sys.path)   #查看python环境变量列表,第一个空为当前目录

6.表达式 if...else...

  随机数:import random

      age = int(random.uniform(0,120))

7.表达式 for循环

  range控制i, i不能控制range

  break结束所有循环,continue结束当次循环

原文地址:https://www.cnblogs.com/wnzhong/p/5836070.html