python学习之输入输出

1. ‘,’ 和 ‘+’在输出字符串中的区别

* ‘,’ 相当于在两个字符串之间加了一个空格 ‘ ’

>>>print("This is a pen","and this is an apple.")
This is a pen and this is an apple.  

* ‘+’相当于直接连接两个字符串

>>>print("This is a pen","and this is an apple.")
This is a penand this is an apple.  

 

2.print(“hello” , end='')

end='str' 表示输出以str 结束 ,且不会换行(python 输出默认换行)

因此常用 end =' '  ,使输出不换行

print("hello")
print("world")
print("hello",end='yes')
print("world",end='no')
hello
world
helloyesworldno

 

 

3.输入input()

>>> name = input()
clearlove
>>> print(name)
clearlove

注:如果输入一个数字,会视这个数字为一个字符串,不能当成整形计算。但可以用 int() 强制转换。 

例如:

>>> num = input()
365
>>> print(num+35)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly

>>> num = int(input()) 365 >>> print(num+35) 400

 

 

 

 

posted @ 2018-02-06 20:55  HeyAndy  阅读(80)  评论(0)    收藏  举报