python函数示例_使用Python中的示例的input()函数

python函数示例

Python input()函数 (Python input() function)

input() function is a library function, it is used to get the user input, it shows given message on the console and wait for the input and returns input value in string format.

input()函数是一个库函数,用于获取用户输入,它在控制台上显示给定的消息并等待输入,并以字符串格式返回输入值。

Syntax:

句法:

    input(prompt)

Parameter(s): promot – a string value/message that will display on the console.

参数: promot –将在控制台上显示的字符串值/消息。

Return value: str – it returns user input in string format.

返回值: str –以字符串格式返回用户输入。

Example:

例:

    Input:
text = input("Input any text: ")
# if user input is "Hello world!"
print("The value is: ", text)
Output:
Input any text: Hello world!

Example 1: Input a string and print it and its type

示例1:输入一个字符串并打印它及其类型

# python code to demonstrate example
# of input() function
# user input
text = input("Input any text: ")
# printing value 
print("The value is: ", text)
# printing type
print("return type is: ", type(text))

Output

输出量

Input any text: Hello world!
The value is:  Hello world!
return type is:  <class 'str'>

Example 2: Input different of types of values and print them along with their types

示例2:输入不同类型的值,并将其与它们的类型一起打印

# python code to demonstrate example
# of input() function
# input 1
input1 = input("Enter input 1: ")
print("type of input1 : ", type(input1))
print("value of input1: ", input1)
# input 2
input2 = input("Enter input 2: ")
print("type of input2 : ", type(input2))
print("value of input2: ", input2)
# input 3
input3 = input("Enter input 3: ")
print("type of input3 : ", type(input3))
print("value of input3: ", input3)

Output

输出量

Enter input 1: 12345
type of input1 :  <class 'str'>
value of input1:  12345
Enter input 2: 123.45
type of input2 :  <class 'str'>
value of input2:  123.45
Enter input 3: Hello [email protected]#$
type of input3 :  <class 'str'>
value of input3:  Hello [email protected]#$

输入整数和浮点值 (Input integer and float values)

There is no direct function that can be used to take input in either in an integer value or in a float value.

没有直接函数可用于以整数值或浮点值进行输入。

input() function takes an input from the user of any type like integer, float, string but returns all values in string format. If we need values in an integer or float types, we need to convert them.

input()函数从用户获取任何类型的输入,例如整数,浮点数,字符串,但以字符串格式返回所有值。 如果我们需要整数或浮点类型的值,则需要对其进行转换。

To convert input in an integer, we use int() function.

为了将输入转换为整数,我们使用int()函数 。

To convert input in a float, we use float() function.

为了将输入转换为浮点数,我们使用float()函数 。

Example 3: Python code to input integer and float values

示例3:用于输入整数和浮点值的Python代码

# python code to demonstrate example
# of input() function
# input an integer value
num = int(input("Enter an integer value: "))
print("type of num: ", type(num))
print("value of num: ", num)
# input a float value
num = float(input("Enter a float value: "))
print("type of num: ", type(num))
print("value of num: ", num)

Output

输出量

Enter an integer value: 12345
type of num:  <class 'int'>
value of num:  12345
Enter a float value: 123.45
type of num:  <class 'float'>
value of num:  123.45

翻译自: https://www.includehelp.com/python/input-function-with-example.aspx

python函数示例

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/546271.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Python pandas DateFrame查询数据df.loc的5种方法

# _*_coding:utf-8_*_ import pandas as pd# 自定义函数 def func(df):return df[temperature] < 32# Press the green button in the gutter to run the script. if __name__ __main__:data {date: [2022-08-21, 2022-08-22, 2022-08-23],weather: ["晴", &quo…

想读Spring源码?先从这篇「 极简教程」开始吧...

为什么要阅读源码&#xff1f;这是一个有趣的问题&#xff0c;类似的问题还有&#xff0c;为什么要看书&#xff1f;为什么要爬山&#xff1f; 这也是一个哲学问题&#xff0c;我想每个人都有不同的答案&#xff0c;下面我是对阅读源码好处的一些思考。 &#xff08;PS&#x…

Python pandas DateFrame新增数据列

下面代码在Linux下运行 # _*_coding:utf-8_*_ import os import pandas as pd# 自定义函数 def func(x):if x[temperature] > 30:return 高温if x[temperature] < 10:return 低温return 常温# Press the green button in the gutter to run the script. if __name__ __…

python函数示例_带Python示例的float()函数

python函数示例Python float()函数 (Python float() function) float() function is a library function in Python, it is used to get a float value from a given number or a string. It accepts either a string (that should contain a number) or a number and returns …

ALP规则的验证

实验1&#xff1a;ALP规则的验证实验目标创建本地用户jack、tom、mike,创建本地组group1&#xff0c;并把所建的用户加入到group1中&#xff0c;通过ALP规则实现以上用户对e:\share\1.txt 文件内容读取和写入权限实验环境略实验步骤一、 创建本地用户jack、tom、mike右击计算机…

6大分布式定时任务对比

作者 | sharedCode来源 | blog.csdn.net/u012394095/article/details/79470904分布式定时任务简介 把分散的&#xff0c;可靠性差的计划任务纳入统一的平台&#xff0c;并实现集群管理调度和分布式部署的一种定时任务的管理方式&#xff0c;叫做分布式定时任务。常见开源方案 e…

Python利用pandas获取每行最大值和最小值

知识点 1.找出每一行最大值和对应的列索引&#xff1a; #找出每行最大值对应的索引 df[max_idx]df.idxmax(axis1) #取出该最大值 df[max_val]df.max(axis1)2.找出每一行最小值和对应的列索引&#xff1a; # 找出每行最小值对应的索引 df[min_idx]df.idxmin(axis1) # 取出该最…

一文搞懂 ThreadLocal 原理

当多线程访问共享可变数据时&#xff0c;涉及到线程间同步的问题&#xff0c;并不是所有时候&#xff0c;都要用到共享数据&#xff0c;所以就需要线程封闭出场了。数据都被封闭在各自的线程之中&#xff0c;就不需要同步&#xff0c;这种通过将数据封闭在线程中而避免使用同步…

python中assert_在Python中带有示例的assert关键字

python中assertPython断言关键字 (Python assert keyword) assert is a keyword (case-sensitive) in python, it is used to debug the code. Generally, it can be used to test a condition – if a condition returns False – it returns an Assertion Error (AssertionEr…

单域MPLS ***数据转发实验分析

MPLS 数据详细转发流程示意图&#xff1a;配置思路&#xff1a;在自治系统AS100中配置IGP&#xff0c;使得两台PE路由器的lo 0接口路由可达&#xff1b;两台PE路由器路由可达后&#xff0c;在两台PE路由器之间建立MP-iBGP邻居关系&#xff0c;用来传输V4路由&#xff1b;AS100中…

python中list函数_list()函数以及Python中的示例

python中list函数Python list()函数 (Python list() function) list() function is a library function, it is used to create a list, it accepts multiple elements enclosed within brackets (because list() takes only one argument. Thus, the set of elements within b…

IDEA 终于支持中文版和 JDK 直接下载了(太方便了)附新版介绍视频

这是我的第 48 篇原创文章。IDEA 2020.1 经过了漫长的打磨终于发布正式版了&#xff0c;而这次的版本不止直接支持 Java 14&#xff0c;还带来了两个重量级的功能&#xff1a;官方中文版支持和 JDK 直接下载。在之前的开发中&#xff0c;当我们需要下载 JDK 时&#xff0c;通常…

【BO】WEBI文件打开时提示Illegal access错误

在infoview中打开WEBI文件时&#xff0c;提示如下错误。 通过查看SCN&#xff0c;找到错误原因是CMC中有一个服务没有启动。 启动这个服务即可&#xff1a; WebIntelligenceProcessingServer转载于:https://www.cnblogs.com/uzipi/p/3905513.html

华为交换机链路聚合使用ENSP模拟器进行实验

一、简介 链路聚合(Eth-Trunk)是将多个物理接口捆绑为一个逻辑接口,实现增加链路带宽,提高可靠性,提供负载分担的目的。 二、华为ENSP模拟器仿真图 华为交换机LSW1和LSW2端口G0/0/2、G0/0/3实现链路聚合,这2个交换机通过静态路由实现2个不同网段V10、V20互通。 三、华…

为什么工作很卖力,最后还晋升不了?

作者 | 军哥来源 | 军哥手记&#xff08;公众号ID&#xff1a;zxhy_cj&#xff09;最近写文章多了一些思考&#xff0c;要写对大家有价值的、有启发、有思考的东西&#xff0c;希望读者朋友们enjoy&#xff01;为什么自我感觉良好&#xff0c;可是晋升没我&#xff1f;感觉老板…

python 示例_Python中带有示例的class关键字

python 示例Python类关键字 (Python class keyword) class is a keyword (case-sensitive) in python, it is used to define a class, when we need to define a class, before the class name - we must have to use class keyword. class是python中的一个关键字(区分大小写)…

基于Java的数据采集(终结篇)

关于写过关于JAVA采集入库的三篇文章&#xff1a; 基于Java数据采集入库&#xff08;一&#xff09;&#xff1a;http://www.cnblogs.com/lichenwei/p/3904715.html 基于Java数据采集入库&#xff08;二&#xff09;&#xff1a;http://www.cnblogs.com/lichenwei/p/3905370.ht…

华为交换机、路由器配置单臂路由实现不同网段通信

一、eNSP模拟器仿真图 二、华为交换机配置 //批量创建VLAN [Huawei]vlan batch 10 20 //PC1电脑与交换机连接端口配置 [Huawei]interface GigabitEthernet0/0/2 [Huawei-GigabitEthernet0/0/2]port link-type access [Huawei-GigabitEthernet0/0/2]port default vlan 10 [Huaw…

python中的Lambda表达式/函数

Explanation: 说明&#xff1a; In python, there is a function named Lambda. Lambda function is an anonymous function - that means the function which does not have any name. 在python中&#xff0c;有一个名为Lambda的函数。 Lambda函数是一个匿名函数-表示该函数…

IDEA 正式版终于支持中文版和 JDK 直接下载了(太方便了)附介绍视频

IDEA 2020.1 经过了漫长的打磨终于发布正式版了&#xff0c;而这次的版本不止直接支持 Java 14&#xff0c;还带来了两个重量级的功能&#xff0c;官方中文版支持和 JDK 直接下载。 在之前的开发中&#xff0c;当我们需要下载 JDK 时&#xff0c;通常的步骤是这样的&#xff1…