x=5
#用元组赋值
(x,y)=(5,10)
SyntaxError: invalid character in identifier(x,y)=(5,10)
x
5y
10x,y=8,2
x
8y
2[x,c,v]=[2,4,5]
x
2c
4v
5a,b,c=‘uke’
a
‘u’b
‘k’c
‘e’#序列赋值
a,b,c=‘ying’
Traceback (most recent call last):
File “<pyshell#19>”, line 1, in
a,b,c=‘ying’
ValueError: too many values to unpack (expected 3)s=‘ying’
a,b,*c=s
a
‘y’b
‘i’c
[‘n’, ‘g’]#扩展序列解包赋值
a,*b,c=s
b
[‘i’, ‘n’]a
‘y’c
‘g’#解包后是一个列表
type©
<class ‘str’>type(b)
<class ‘list’>#不够的情况
a,b,c,d=‘usa’
Traceback (most recent call last):
File “<pyshell#34>”, line 1, in
a,b,c,d=‘usa’
ValueError: not enough values to unpack (expected 4, got 3)a,b,c,*d=‘asa’
d
[]a
‘a’a,b,*c=‘uke’
c
[‘e’]type©
<class ‘list’>#多目标赋值
a=‘uke’
b=‘uke’
a is b
True#int性边界是256,字符串边界是三个字符
a=b=[]
a.append(3)
a
[3]b
[3]a=[]
b=[]
a.append()
Traceback (most recent call last):
File “<pyshell#55>”, line 1, in
a.append()
TypeError: append() takes exactly one argument (0 given)a.append(1)
a
[1]b
[]#函数调用
len([1,2,3])
3#方法调用
b.append([1.2])
b
[[1.2]]s=‘hello’
y=‘你好’
print(s,y)
hello 你好print(s,y,sep=’|00’)
hello|00你好print(s,y,file=open(‘G:\e.txt’))
Traceback (most recent call last):
File “<pyshell#68>”, line 1, in
print(s,y,file=open(‘G:\e.txt’))
FileNotFoundError: [Errno 2] No such file or directory: ‘G:\e.txt’#语句
score=40
if(score<60)
不及格if(score<60):
print(‘不及格’)
elif:
‘及格’#三元表达式
x=‘xunhuanyuju’
while x:
print(x,end=’’)
x=x[1:]
x=10
while x:
x-=1
if x%2!=0:
continue
print(x,end=’’)
while True:
name=input(‘请输入您的姓名:’)
if name==‘stop’:
break
age=input(‘请输入您的年龄:’)
print(‘您好:{},您的年龄:{},欢迎学习’.format(name,age))
for x in range(1,5):
if x6:
print(‘有这个数字’,x)
break
else:
print(‘未找到’)
for x in [1,2,3,4]:
print(x,end=’’)
sum=0
for x in [1,2,3,4,5]:
sum+=x
print(sum)
#遍历字典表
emp={‘name’:‘jerry’,
‘department’:‘technoloty’,
‘job’:‘development’,
‘salary’:9000}
for key in emp.keys():
print(’{}>{}’.format(key,emp[key]))
s=‘xuexi’
for i,j in enumerate(s):
print(’{}) {}’.format(i+1,j))