zoukankan      html  css  js  c++  java
  • Python输入/输出语句

    Python输出语句print函数

    • print()函数基本使用

        打印整形数据

        打印浮点型数据

        打印字符型数据

    >>> print(12)
    12
    >>> print(12.5)
    12.5
    >>> print('B')
    B
    >>> print('WWW.baidu.com')
    WWW.baidu.com
    >>> x=12
    >>> print(12)
    12
    >>> y=12.88
    >>> print(y)
    12.88
    >>> z='www.bling.com'
    >>> print(z)
    www.bling.com
    >>> print z
    www.bling.com
    >>> print x,y,z
    12 12.88 www.bling.com
    >>> print(z,y,z)
    ('www.bling.com', 12.88, 'www.bling.com')

    • print格式化输出

      print(format(val,fomat_modifier))

        var:值

        fomat_modifier:格式字

      print(12.34567,'m.nf')

        m:表示占位数量(m),m<有效位时,左对齐;m>有效位时,右对齐

        n:表示精度(n)

      print x,y  '逗号'连接输出

    >>> print(format(12.345678,'6.2f'))
     12.35
    >>> print(format(12.345678,'6.3f'))
    12.346
    >>> print(format(12.345678,'6.9f'))
    12.345678000
    >>> print(format(12.345678,'6.0f'))
        12
    >>> print(format(12.345678,'6.3f'))
    12.346
    >>> print(format(12.345678,'6.2f'))
     12.35
    >>> print(format(12.345678,'9.2f'))
        12.35
    >>> print(format(12.345678,'3.2f'))
    12.35
    >>> print(format(12.345678,'5.2f'))
    12.35

      print()格式化输出format

        print(format(val,fomat_modifier))

        print(format(0.3456,'.2%'))

    >>> print(format(0.3456,'.2%'))
    34.56%
    >>> print(format(0.3456,'.3%'))
    34.560%
    >>> print(format(0.3456,'.6%'))
    34.560000%
    >>> print(format(0.3456,'6.3%'))
    34.560%
    >>> print(format(0.3456,'6.1%'))
     34.6%
    • Python输入函数

      re = raw_input(prompt)

      prompt:提示字符,从键盘读取数据

      re:返回值,返回字符串 

      类型转换:int()(转为整形)、float()(浮点型)

    >>> re = raw_input()
    www.bling.com
    >>> print(re)
    www.bling.com
    >>> type(re)
    <type 'str'>
    >>> age = raw_input('your age :')
    your age :22
    >>> age = age +1
    
    Traceback (most recent call last):
      File "<pyshell#11>", line 1, in <module>
        age = age +1
    TypeError: cannot concatenate 'str' and 'int' objects
    >>> age = int(age)
    >>> age
    22
    >>> age = age +1
    >>> age
    23
    >>> type(age)
    <type 'int'>
    >>> age = int(raw_input('PLZ input your age :'))
    PLZ input your age :23
    >>> type(age)
    <type 'int'>
    >>> f1 = float('12.35')
    >>> type(f1)
    <type 'float'>
    >>> weight = float(raw_input('Plz input your weight :'))
    Plz input your weight :70.01
    >>> print(weight)
    70.01
    >>> type(weight)
    <type 'float'>
    >>> 
  • 相关阅读:
    Google analytics平均页面停留时间为何是0
    用易语言拦截窗口消息(带例程)
    OS + Linux RHEL / RedHat Enterprise 5 / 6 / 6.3
    Oracle学习教程:动态SQL与游标详解
    图解Oracle数据库(二)
    Oracle数据库中listener.ora sqlnet.ora tnsnames.ora的区别
    正确理解javascript的this关键字
    深入理解Javascript之this关键字
    Oracle中动态SQL详解
    oracle维护常用SQL语句(查看系统表和视图)
  • 原文地址:https://www.cnblogs.com/yangml/p/3849971.html
Copyright © 2011-2022 走看看