>>> welcome_str = "Welcome you" >>> welcome_str[0] 'W' >>> welcome_str[1] 'e' >>> welcome_str[len(welcome_str)-1] 'u' >>> welcome_str[:4] 'Welc' >>> a = "python" >>> a*3 'pythonpythonpython' >>> git_list = ["qiwsir","github","io"] >>> git_list[0] 'qiwsir' >>> git_list[len(git_list)-1] 'io' >>> git_list[0:2] ['qiwsir', 'github'] >>> b = ['qiwsir'] >>> b*7 ['qiwsir', 'qiwsir', 'qiwsir', 'qiwsir', 'qiwsir', 'qiwsir', 'qiwsir']
>>> first = "hello,world" >>> welcome_str 'Welcome you' >>> first+","+welcome_str #用+号连接str 'hello,world,Welcome you' >>> welcome_str #原来的str没有受到影响,即上面的+号连接后从新生成了一个字符串 'Welcome you' >>> first 'hello,world' >>> language = ['python'] >>> git_list ['qiwsir', 'github', 'io'] >>> language + git_list #用+号连接list,得到一个新的list ['python', 'qiwsir', 'github', 'io'] >>> git_list ['qiwsir', 'github', 'io'] >>> language ['python'] >>> len(welcome_str) #得到字符数 11 >>> len(git_list) #得到元素数 3
>>> git_list
['qiwsir', 'github', 'io']
>>> git_list.append("python")
>>> git_list
['qiwsir', 'github', 'io', 'python']
>>> git_list[1]
'github'
>>> git_list[1] = 'github.com'
>>> git_list
['qiwsir', 'github.com', 'io', 'python']
>>> git_list.insert(1,"algorithm")
>>> git_list
['qiwsir', 'algorithm', 'github.com', 'io', 'python']
>>> git_list.pop()
'python'
>>> del git_list[1]
>>> git_list
['qiwsir', 'github.com', 'io']
>>> welcome_str
'Welcome you'
>>> welcome_str[1] = 'E'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>> del welcome_str[1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object doesn't support item deletion
>>> welcome_str.append("E")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'append'
>>> welcome_str 'Welcome you' >>> welcome_str[0] + "E" + welcome_str[2:] #从新生成一个str 'WElcome you' >>> welcome_str #对原来的没有任何影响 'Welcome you'
>>> matrix = [[1,2,3],[4,5,6],[7,8,9]] >>> matrix = [[1,2,3],[4,5,6],[7,8,9]] >>> matrix[0][1] 2 >>> mult = [[1,2,3],['a','b','c'],'d','e'] >>> mult [[1, 2, 3], ['a', 'b', 'c'], 'd', 'e'] >>> mult[1][1] 'b' >>> mult[2] 'd'
split(...) S.split([sep [,maxsplit]]) -> list of strings Return a list of the words in the string S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result.
>>> line = "Hello.I am qiwsir.Welcome you."
>>> line.split(".") #以英文的句点为分隔符,得到list
['Hello', 'I am qiwsir', 'Welcome you', '']
>>> line.split(".",1) #这个1,就是表达了上文中的:If maxsplit is given, at most maxsplit splits are done.
['Hello', 'I am qiwsir.Welcome you.']
>>> name = "Albert Ainstain" #也有可能用空格来做为分隔符
>>> name.split(" ")
['Albert', 'Ainstain']
"[sep]".join(list)
>>> name ['Albert', 'Ainstain'] >>> "".join(name) #将list中的元素连接起来,但是没有连接符,表示一个一个紧邻着 'AlbertAinstain' >>> ".".join(name) #以英文的句点做为连接分隔符 'Albert.Ainstain' >>> " ".join(name) #以空格做为连接的分隔符 'Albert Ainstain'
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有