标签:targe 格式 net 导入模块 赋值 逗号 pytho port 轻量级
>>> name="Gumby" >>> salutation="Mr." >>> greeting="Hello," ##同时输出三个变量 >>> print greeting + salutation + name Hello,Mr.Gumby # 普通输出,相邻两个变量之间有空格 >>> print greeting, salutation, name Hello, Mr. Gumby # 逗号输出,相邻两个变量之间有空格 >>> print "%s %s %s" % (greeting, salutation, name) Hello, Mr. Gumby # %格式化字符串输出,有无空格看""内如何定义 ##解决空格问题 >>> greeting="Hello" >>> print greeting , "," , salutation , name Hello , Mr. Gumby >>> print greeting + "," , salutation , name Hello, Mr. Gumby ##语句结尾处打逗号会去掉回车 text.txt: print "Hello,", print "world" cmd: py text.txt Hello, world
1. import somemodule 2. from somemodule import somefunction 3. from somemodule import somefunction, anotherfunction, yetanotherfunction 4. from somemodule import *
## module1.open() module2.open() ## from module1 import open as open1 open1() from module2 import open as open2 open2()
>>>values = 1,2,3 >>>values (1,2,3) >>>x, y, z = values >>>print x, y, z 1 2 3 ##交换变量 >>>x, y = y, x >>>print x, y, z 2 1 3 ##当函数返回序列或映射时,序列解包很好用 >>> dic = {‘name‘:{‘one‘:‘One‘,‘two‘:‘Two‘},‘pho‘:{1:1,2:2}} >>> key, values = dic.popitem() >>> key ‘pho‘ >>> values {1: 1, 2: 2} >>> key, values = dic.popitem() >>> key ‘name‘ >>> values {‘two‘: ‘Two‘, ‘one‘: ‘One‘}
>>>x = y = somefunction()
标签:targe 格式 net 导入模块 赋值 逗号 pytho port 轻量级
原文地址:https://www.cnblogs.com/Sakurar/p/11829550.html