有没有一种方法可以格式化python中的输入?

时间:2020-01-17 07:14:28

标签: python-3.x input user-input

在python中的输出过程中,按Enter键后,光标会自动移至下一行。 采取以下程序,

n = input()
cost = float(input())
qty = int(input())

输出为:

product name
12.5
2

但是我想要这样的输出,而是使用制表符代替。

product name            12.5        2

是否可以通过这种方式格式化python输入?

编辑:我不想使用打印来格式化输出,在输入数据本身时(即在输入过程中),我不希望光标按制表符空格移动。

3 个答案:

答案 0 :(得分:0)

使用这种打印功能

print('Something to print', end='\t')

或仅使用类似的内容

print(f'product name\t\t {value1}\t {value2}')

答案 1 :(得分:0)

简单的方法就是使用

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
        googlePlayServicesVersion = "11.8.0"
    }
    repositories {
        google()
        jcenter()
        maven {
           url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'

        classpath 'com.google.gms:google-services:4.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        classpath 'io.fabric.tools:gradle:1.25.4'
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            // Add jitpack repository (added by react-native-spinkit)
            url "https://jitpack.io"
        }
        maven {
            url 'https://maven.google.com/'
        }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

答案 2 :(得分:0)

也许您以后可以解析输入内容吗?因此,您可以在键入时保留缩进(通常使用TAB键即可)。之后,您可以将其存储在变量中,.split()并使用它进行任何操作。