python第四天基本语句

x=5
#用元组赋值
(x,y)=(5,10)
SyntaxError: invalid character in identifier

(x,y)=(5,10)
x
5

y
10

x,y=8,2
x
8

y
2

[x,c,v]=[2,4,5]
x
2

c
4

v
5

a,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

c=‘uke.cc
d=‘uke.cc
c is d
False

#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))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值