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 浮点数,约等于小数

     

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

  • 相关阅读:
    shell遍历文件夹并执行命令
    安装PIL的坑
    iptables不小心把127.0.0.1封了,导致redis连不上
    python读取中文
    不要在基类析构函数中调用纯虚函数,否则运行时会报错“pure virtual method called”
    阿里云64位centos6.3系统上编译安装redis
    Git
    Easy Mock
    Sortable
    几个框架
  • 原文地址:https://www.cnblogs.com/darkalex001/p/7493313.html
Copyright © 2011-2022 走看看