输入:
input:会将用户输入的任意内容都存成字符串类型
name=input(‘请输您的账号:’)
print(name,type(name))
输出:
res=11111
print(res,1,2,3,4,5,6)
print('hello world',end=' ') // end=' ' 不换行 end='\n'换行
print('my name is xxx')
格式化输出
name=input(‘请输入您的名字:’)
age=input(‘请输入您的年龄:’)
msg='my name is %s my age is %s' %(name,age) // %占位符 %s表示任意数据类型
print(msg)
print(my age is %s' %s10)
print('my age is %s' %[1,2,3])
print('my age is %d' %[1,2,3])
注意:
#%s字符串占位符:可以接收字符串,也可接收数字 print('My name is %s,my age is %s' %('egon',18)) #%d数字占位符:只能接收数字 print('My name is %s,my age is %d' %('egon',18)) print('My name is %s,my age is %d' %('egon','18')) #报错 #接收用户输入,打印成指定格式 name=input('your name: ') age=input('your age: ') #用户输入18,会存成字符串18,无法传给%d print('My name is %s,my age is %s' %(name,age)) #注意: #print('My name is %s,my age is %d' %(name,age)) #age为字符串类型,无法传给%d,所以会报错