print
python使用内置函数print来输出内容
如:
print( “hello”)
print语句的使用
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
print(value,…)##可以输出多个
print(‘张三’,‘李四’,‘nihao’,‘hello’)
#sep参数用来表示输出时,每个值之间使用那个字符作为分离,默认使用空格符
##end参数用来表示执行完一个print语句和,接下来要输出的字符,默认为 \n 表示换行
input
python使用内置函数input来接收用户的输入
def input(*args, **kwargs):
要注意的时,input中不论用户输入的是什么内容,输入的内容都是字符串类型(str)
print('--字符串空格--')
print("hello world") ##字符串包括空格
print("hello","world") ##逗号用于隔离字符串
print() ##表示空一行
print("--字符串拼接--")
print("hello""world") ##字符串间默认拼接
print("hello"+"world")##+号用于字符串拼接
print()
print("--print中\\n换行--") ##用第一个\表示转义\n,第二个\n表示换行
print("a\nb\nc") ##打印为a,换行b,换行c
print("a\\nb\\nc") ##打印为a\nb\nc
print()
print("---------") #表示分隔符
print('--print中*的用法--')
print('3' * 5 ) ##print中字符用*号表示重复多少次
print(3*5) ##print中数字用*表示求积算法
print()
print('print中end的用法')
print('Nothing is impossible to a willingheart!')
print('Nothing is impossible to a willingheart!',end='')
print('Nothing is impossible to a willingheart!',end='\n')
print('Nothing is impossible to a willingheart!')
print('----------')
print('--print中sep表示两单词间用什么字符隔开')
print('hello','world',sep="@@@")
print("file\n","abc","fff",sep="@@@\n")
输出
number=input("please input a number:")
print(number)
print(type(number)) ##input,默认是字符类型
#print(number+10)#报错,字符不能与数字做运算
print(int(number)+10)##int(number)转换类型,将字符串10转换为数字10
print(number+str(10))##将数字10转换为字符串实现拼接
##把input的str类型更改为int类型
#int(shuzi)=input("输入:")
#print(shuzi+10)##这两步为错误,正解如下
shuzi=int(input("shuzi= "))
print(shuzi+10)