0%

python grammar toolbook

Some useful grammars in Python

Input

1
2
3
4
5
6
a,b=input().split()
print(a,b)
## way 2
s=input().split()
a,b=list(map(int,s))
print(a,b)

List

image-20240224095825541

image-20240224104855878

List slice:

image-20240224105303773

Copy:

image-20240224105731333

Tuple

Elements in tuples cannot be altered,while it could be switched into list to do so.

Inner functions are mostly the same between the two data structures.

image-20240224111238019

String

image-20240224113213331

image-20240224113501087

Judge functions(Inner):

image-20240224113532965

Transformer:

image-20240224113647852

查找类方法:

image-20240228172607722

From string to list:

image-20240224130951659

image-20240224131441588

当t转换为list类型之后,可以利用str.join(t)将序列的每个元素用str连接起来

Format格式化

image-20240228172156115

同时也可以先用实际意义的变量名作为占位符,随后format实际上是一个后赋值的操作

image-20240228172400739

字典