美文网首页
简析python3中的输入输出

简析python3中的输入输出

作者: HilaryLi | 来源:发表于2017-10-19 23:33 被阅读0次
    果然一天不练手就生,好久没有写代码了,今天上机测试竟然连最简单的都不会了。于是想着来写一个博文总结回顾一下并且方便以后的查找。
    • python3

    输出

    ①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
    
    • print输出后无换行符号
    >>>for i in range(0,6):
    >>>     print(i,end=" ")
    0 1 2 3 4 5
    
    • str.format
    >>>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       #不知道为什么后面还有一个字符串长度
    

    输入

    • input函数
    >>>x = input() #input hilary
    >>>print(x)
    hilary
    

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

    • isdigit函数
    c578ce0c8253f458f16f7c5e3a2fefb6_r.jpg.png
    • 标准化输入sys.stdin
    • 一行输入多个值
    #输出的是字符串,要想读取的是数值,可以像这样: 
    >>>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]
    

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

    相关文章

      网友评论

          本文标题:简析python3中的输入输出

          本文链接:https://www.haomeiwen.com/subject/eywpuxtx.html