python输入split_使用Python中的split()方法从用户获取多个输入

python输入split

The task is to take multiple inputs from the user, for this we can use split() method.

任务是从用户那里获取多个输入 ,为此,我们可以使用split()方法

split()方法 (split() method)

split() method is a library method in Python, it accepts multiple inputs and brakes the given input based on the provided separator if we don’t provide any separator any whitespace is considered as the separator.

split()方法是Python中的一种库方法,如果我们不提供任何分隔符,则任何空白都被视为分隔符,它接受多个输入并根据提供的分隔符制动给定输入。

Syntax:

句法:

    input().split([separator], [maxsplit])

Here, separator and maxsplit are the optional parameters, they can be used for the specified purposes.

在这里, separator和maxsplit是可选参数,它们可用于指定目的。

Example without using separator

不使用分隔符的示例

# input two integer numbers and print them
a, b = input('Enter two integer numbers: ').split()
print("a = ",a, ",b = ",b)

# input name, age and percentages of the student 
# and print them
name, age, perc = input("Enter student's details: ").split()
print("Name: ", name)
print("Age: ", age)
print("Percentage: ", perc)

Output

输出量


  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值