简析python3中的输入输出

2017-10-19  本文已影响0人  HilaryLi
果然一天不练手就生,好久没有写代码了,今天上机测试竟然连最简单的都不会了。于是想着来写一个博文总结回顾一下并且方便以后的查找。

输出

①print()函数

>>> str = "hilary"
>>>print(str)
hilary

>>>s = "hello"
>>>repr(s)#Python具有将任何值转换为字符串的方法:将其传递给repr()或str()函数
"'hello'"

example:

>>>x = 10 * 3.25
>>>y = 200 * 200
>>>s = 'The Value of x is' + repe(x)+',and y is'+repr(y)+'...'
>>>print(s)
The Value of x is 32.5,and y is 40000....
>>> str = "the length of %s is %d"%("hello world",len("hello world"))#注意后面参数部分%的前面没有逗号,参数都放在后面一个括号中
>>>print(str)
the length of hello world is 11
>>>for i in range(0,6):
>>>     print(i,end=" ")
0 1 2 3 4 5
>>>print('We are the {} who say "{}!"'.format('knights', 'Ni'))
We are the knights who say "Ni!"
>>>list1 = [1,2,3,'python']
>>>print(list1)
[1,2,3,'python']
>>>import sys
>>>sys.stdout.write("hello")
hello5       #不知道为什么后面还有一个字符串长度

输入

>>>x = input() #input hilary
>>>print(x)
hilary

s.isalnum() 所有字符都是数字或者字母
s.isalpha() 所有字符都是字母
s.isdigit() 所有字符都是数字
s.islower() 所有字符都是小写
s.isupper() 所有字符都是大写
s.istitle() 所有单词都是首字母大写,像标题
s.isspace() 所有字符都是空白字符、\t、\n、\r

c578ce0c8253f458f16f7c5e3a2fefb6_r.jpg.png
#输出的是字符串,要想读取的是数值,可以像这样: 
>>>a, b, c = map(int, input().split())#否则input().split()即可
1 2 3
>>>input_list = map(int, input().split()) 
1 2 3
>>>input_list
[1,2,3]

暂时想到这么多,再有想到的一定及时更新~

上一篇下一篇

猜你喜欢

热点阅读