zoukankan      html  css  js  c++  java
  • 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 浮点数,约等于小数

     

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

  • 相关阅读:
    进程与线程
    the art of seo(chapter seven)
    the art of seo(chapter six)
    the art of seo(chapter five)
    the art of seo(chapter four)
    the art of seo(chapter three)
    the art of seo(chapter two)
    the art of seo(chapter one)
    Sentinel Cluster流程分析
    Sentinel Core流程分析
  • 原文地址:https://www.cnblogs.com/darkalex001/p/7493313.html
Copyright © 2011-2022 走看看