python.列表和格式化输出练习

列表list练习

student_inf = [‘bob’, ‘22’, [‘play’, ‘sleeep’, ], ‘abc’, ‘21’, [‘sleep’, “basketball”, ‘ball’]]

print(student_inf[0:3])

print(student_inf[:3])
print(student_inf[2][0])

x=257
y=257
print(id(x),id(y))

格式化输出

name=input(‘please input your username:’)
age=input(‘please input your age:’)
print(‘my name is’,name,‘my age is’,age)
print(‘my name is %s,my age is %s’ % (name,age))

print(‘my name is %s,my age is %s’ %(name,age))

‘’’
my name is 输入的用户名,my age is 输入的年龄
‘’’

print(‘my name is %s my age is %s’ %(18,‘egon’))

print(‘my name is %s my age is %d’ %(‘egon’,18))

print(‘my name is %s my age is %s’ %(‘egon’,18))

print(‘my name is %s my age is %s’ %(‘egon’,[1,2,3])) # %s可以接收任意类型的值

你可能感兴趣的:(python学习)