Python 笔记2
来源:互联网 发布:衣柜画图软件 编辑:程序博客网 时间:2024/06/15 18:51
变量和局部变量
<span style="font-size:12px;">#coding=utf-8#!/usr/bin/python total = 0; # This is global variable.# 可写函数说明def sum( arg1, arg2 ): #返回2个参数的和." total = arg1 + arg2; # total在这里是局部变量. print "Inside the function local total : ", total return total; #调用sum函数sum( 10, 20 );print "Outside the function global total : ", total <em><strong>以上实例输出结果:</strong></em>Inside the function local total : 30Outside the function global total : 0</span>
Python 模块
模块support.pydef print_func( par ): print "Hello : ", par return
import 语句
#coding=utf-8#!/usr/bin/python # 导入模块import support # 现在可以调用模块里包含的函数了support.print_func("Zara")以上实例输出结果:Hello : Zara
From…import 语句
要导入模块fib的fibonacci函数,使用如下语句:from fib import fibonacci这个声明不会把整个fib模块导入到当前的命名空间中,它只会将fib里的fibonacci单个引入到执行这个声明的模块的全局符号表。
input函数
input([prompt]) 函数和raw_input([prompt]) 函数基本可以互换,但是input会假设你的输入是一个有效的Python表达式,并返回运算结果。
打开和关闭文件
file object = open(file_name [, access_mode][, buffering])
access_mode参数:
重命名和删除文件
Python的os模块提供了帮你执行文件处理操作的方法,比如重命名和删除文件。重命名
#coding=utf-8#!/usr/bin/pythonimport os # 重命名文件test1.txt到test2.txt。os.rename( "test1.txt", "test2.txt" )
删除
#coding=utf-8#!/usr/bin/pythonimport os # 删除一个已经存在的文件test2.txtos.remove("text2.txt")
创建
#coding=utf-8#!/usr/bin/pythonimport os # 创建目录testos.mkdir("test")
0 0
- python学习笔记2
- python学习笔记(2)
- Python学习笔记(2)
- python笔记2
- Python笔记(2)
- python笔记2
- python笔记2
- python笔记《2》
- python初学笔记(2)
- 《Think Python》笔记2
- Python笔记2
- Python学习笔记【2】
- Python 基础笔记(2)
- python学习笔记--2
- python学习笔记2
- Python学习笔记[2]
- python学习笔记--2
- python学习笔记2
- IBM TDI RMI - Slow KahaDB access: cleanup took <18058>
- 为什么美国人数秒时习惯说One Mississippi?
- BING: Binarized Normed Gradients for Objectness Estimation at 300fps
- 字符内存大小
- XCode
- Python 笔记2
- Web Scraping With Scrapy and MongoDB
- autoconf和automake的使用教程
- javaee学习之路(六)Servlet过滤器
- abstract类和abstract方法
- llibevent2笔记(linux、windows、android的编译和HTTP client应用)
- Android 网络通信HttpClient的环境配置和注意点
- Device driver development manual simplified version
- Java 线程学习笔记(锁、同步等)