• day05_03 字符串格式化


    pycharm小技巧,一般情况下都需要在代码前注释以下作者以及创建日期

    但是如何让软件默认生成呢?

    格式化输出

    可以用占位符

    %s     string的缩写

    #__author:Administrator
    #date:2017/9/8
    
    name = input("Name:")
    age = input("Age:")
    job = input("Job:")
    salary = input("Salary:")
    
    print(name,age,job,salary)
    
    msg = '''
    -------info of %s------
    Name: %s
    Age: %s
    JOb: %s
    Salary: %s
    -------end------
    ''' % (name,name,age,job,salary)
    
    print (msg)
    

    #__author:Administrator
    #date:2017/9/8
    
    name = input("Name:")
    age = int(input("Age:"))
    job = input("Job:")
    salary = input("Salary:")
    print(name,age,job,salary)
    
    msg = '''
    -------info of %s------
    Name: %s
    Age: %s
    JOb: %s
    Salary: %s
    You will be retired in %s years
    -------end------
    ''' % (name,name,age,job,salary,65-age)
    
    print (msg)
    

    #__author:Administrator
    #date:2017/9/8
    
    name = input("Name:")
    age = int(input("Age:"))
    job = input("Job:")
    salary = input("Salary:")
    
    if salary.isdigit(): #长得想不想数字,比如200d,'200'
        salary = int(salary)
    else:
        print("must input digit")
    
    print(name,age,job,salary)
    
    msg = '''
    -------info of %s------
    Name: %s
    Age: %s
    JOb: %s
    Salary: %s
    You will be retired in %s years
    -------end------
    ''' % (name,name,age,job,salary,65-age)
    
    print (msg)
    

     

    全部注释:ctrl+/

    %d就表示必须输入数字

     占位符:

    %s    s = string

    %d    d = digit 整数

    %f     f = float 浮点数,约等于小数

     

    补充修改以下以上的错误代码

  • 相关阅读:
    ubuntu的apt
    sudo命令
    MySQL导出数据到csv文件
    MySQL导出数据到文件报错
    git_backup.py gitlab项目备份
    java中图像与数组转换
    mongodb转elasticsearch
    impyla-0.14.2.2安装注意事项
    python3.7.3升级 with-openssl openssl-1.0.2a
    hadoop自带性能测试
  • 原文地址:https://www.cnblogs.com/darkalex001/p/7493313.html
Copyright © 2020-2023  润新知