您的位置:首页 > 编程语言 > Python开发

Python开发【第二章】:模块和运算符

2016-08-01 10:24 176 查看

一、模块初识:

Python有大量的模块,从而使得开发Python程序非常简洁。类库有包括三中:

Python内部提供的模块

业内开源的模块

程序员自己开发的模块

1、Python内部提供一个 sys 的模块,

① 其中的 sys.argv 用来捕获执行执行python脚本时传入的参数:

import sys

strings = sys.argv
print(strings)   # 所有参数 类型为列表
# ['start.py', 'hello', 'world']
print(strings[0])   # 脚本名本身
# start.py
print(strings[1])   # 第一个参数
# hello
print(strings[2])   # 第二个参数
# world
print(strings[-1])  # 倒数第一个参数
# world

$ python test.py helo world   执行脚本


sys.stdin信息输入

读取的文件:

#!/usr/bin/python

a = 60            # 60 = 0011 1100
b = 13            # 13 = 0000 1101
c = 0

c = a & b;        # 12 = 0000 1100
print "Line 1 - Value of c is ", c

c = a | b;        # 61 = 0011 1101
print "Line 2 - Value of c is ", c

c = a ^ b;        # 49 = 0011 0001
print "Line 3 - Value of c is ", c

c = ~a;           # -61 = 1100 0011
print "Line 4 - Value of c is ", c

c = a << 2;       # 240 = 1111 0000
print "Line 5 - Value of c is ", c

c = a >> 2;       # 15 = 0000 1111
print "Line 6 - Value of c is ", c


View Code
8、运算符优先级:





点击查看更多内容:Python运算符
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: