>>> 'Let's go!' SyntaxError: invalid syntax >>> "Let's go!" "Let's go!" >>> 'Let's go!' "Let's go!" >>> '''''begin and next end''' 'beginnandnnextnend'
>>> s = "HelloWorld" >>> s[0] = 'h' Traceback (most recent call last): File "<pyshell#123>", line 1, in <module> s[0] = 'h' TypeError: 'str' object does not support item assignment
>>> s 'HelloWorld' >>> L = list(s) >>> L ['H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'] >>> L[0] = 'h' >>> ''.join(L) #这是什么?别着急,下面我们会谈到 'helloWorld'
>>> s = "Hello""World" >>> s 'HelloWorld' >>> s1 = "Hello" >>> s2 = "World" >>> s1s2 Traceback (most recent call last): File "<pyshell#138>", line 1, in <module> s1s2 NameError: name 's1s2' is not defined >>> s1+s2 'HelloWorld'
>>> s = "HelloWorld" >>> len(s) 10 >>> "ll" in s True
>>> s
'HelloWorld'
>>> s.find("l")
2
>>> s.find('w')
-1
>>> s = '''''begin ...then.. ...next.. end...''' >>> s.splitlines() ['begin', '...then..', '...next..', 'end...']
>>> s = "here#there"
>>> s.split('#') # #作为分隔符
['here', 'there']
>>> s = '''''begin
.then.. and
.next.
end'''
>>> s.split() #默认情况将所有换行和空格都分割
['begin', '.then..', 'and', '.next.', 'end']
>>> s = 'HelloWorld' >>> s.lower() 'helloworld' >>> s.upper() 'HELLOWORLD'
>>> L = ['1','33','42'] >>> '+'.join(L) #用+来连接 '1+33+42' >>> L = list(s) #拆开s >>> L ['H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'] >>> ''.join(L) #粘合了。。。 'HelloWorld'
>>> s
'HelloWorld'
>>> s.replace("World","Cheng")
'HelloCheng'
>>> s.replace("world","Cheng") #知道为什么吧...
'HelloWorld'
>>> s = " Hi,I'm Alice! "
>>> s.strip()
"Hi,I'm Alice!"
>>> s.strip("! ") #这是两个字符哦
"Hi,I'm Alice" #少了一个感叹号哦!
>>> name = 'Jonh'
>>> call = '13560300xxx'
>>> "{0}'s telephone number is {1}".format(name,call) # (1)
"Jonh's telephone number is 13560300xxx"
>>> addr = "A103"
>>> "{0}'s telephone number is {1} and his address is {2}".format(name,call,addr) #(2)
"Jonh's telephone number is 13560300xxx and his address is A103"
>>> L = [2,3,5,7]
>>> print("x is {0[0]}, y is {0[2]}".format(L))
x is 2, y is 5
>>> d
{'b': 2, 'a': 1}
>>> print("x is {0[a]}, y is {0[b]}".format(d))
x is 1, y is 2
>>> d = {2:3.5,7:4.5}
>>> print("x is {0[2]}, y is {0[7]}".format(d))
x is 3.5, y is 4.5
>>> print("{0.random}".format(random))
<built-in method random of Random object at 0x022D61F8>
>>> class A:
pass
>>> x = A()
>>> print("The class is {0.__class__}".format(x))
The class is <class '__main__.A'>
>>> print("{name}'s telephone number is {call}".format(name = "Jonh",call = 69993))
Jonh's telephone number is 69993
>>> pi = 3.141592653
>>> print("The pi is {0:10.3f}".format(pi)) # 0:10.3f 表示输出宽度为10,保留三位小数,浮点数
The pi is 3.142
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有