码迷,mamicode.com
首页 > 编程语言 > 详细

Python3(三)

时间:2016-06-27 15:12:21      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

Python 模块

Python 输入和输出

 

代码区:

#
# 点模块名称
# A.B 表示包A中的子模块B
# 几种导包方式

import sound.effects.echo;

form sound.effects import echo;

form sound.effects import *;

###########################

s = erbaohuadou;
print(s); # erbaohuadou
print(repr(s)); # ‘erbaohuadou‘
print(str(1/7)); # 0.14285714285714285
print(1/7); # 0.14285714285714285

x = 5 * 3.25;
y = 200 * 200;

s = The value of x:  + repr(x) + the value of y:  + repr(y)

print(s); # The value of x: 16.25the value of y: 40000

print(狗狗的名字{}二宝的名字{}.format(huadou, erbao)); # 狗狗的名字huadou二宝的名字erbao
print(狗狗的名字{1}二宝的名字{0}.format(erbao, huadou)); # 狗狗的名字huadou二宝的名字erbao
print(狗狗的名字{dogName}二宝的名字{rabName}.format(rabName=erbao, dogName=huadou)); # 狗狗的名

字huadou二宝的名字erbao

import math;
print(圆周率值:{}.format(math.pi)); # 圆周率值:3.141592653589793
print(圆周率值:{!r}.format(math.pi)); # 圆周率值:3.141592653589793
print(圆周率值:{0:.3f}.format(math.pi)); # 圆周率值:3.142

# 格式化数字、表格
table = {item1: 4578, item2: 7244, item3: 2344};

for name,phone in table.items():
    print({0:10}==>{1:10d}.format(name, phone));


# 读写文件
f = open(test.txt, r+);
print(f.read());
# print(f.write(‘this is a text.‘)); # 15
print(f.tell()); # 118
print(f.close()); # None

 

Python3(三)

标签:

原文地址:http://www.cnblogs.com/lqcdsns/p/5619943.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!