您现在的位置是:群英 > 开发技术 > 移动开发
python中的input函数是什么?
Admin发表于 2022-07-22 17:16:13797 次浏览
今天就跟大家聊聊有关“python中的input函数是什么?”的内容,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

两分钟了解python中的input函数

input函数在python中是一个内建函数,其从标准输入中读入一个字符串,并自动忽略换行符。下面我们就来看看input函数的具体用法吧。

#函数input

message = input("Tell me something, and I will repeat it back to you: ")
print(message)
message1 = input()
print(message1)


#创建多行字符串的方式

prompt1="type someting"
prompt2=prompt1+": "+input()
print(prompt2)



prompt = "If you tell us who you are, we can personalize the messages you see."
prompt += "\nWhat is your first name? "
name = input(prompt)
print("\nHello, " + name + "!")



#input默认输入是字符,所以需要字符比较时应当进行类型转换

age=input("How old are you?")
age=int(age)
if(age>=18):
print("You have the right to vote!")
else:
print("Sorry,you have no right to vote!")


#求模运算符

c1=input("Please input a number,and i will do modulo operation for it.")
c1=int(c1)
c2=input("Please input another number,and i will do modulo operation for it.")
c2=int(c2)
c3=c1%c2
print(c3)


#汽车租赁 :编写一个程序,询问用户要租赁什么样的汽车,并打印一条消息,如“Let me see if I can find you a Subaru”。

input("What kind of car would you like to hire?")
print("Let me see if I can find you a Subaru")


#餐馆订位 :编写一个程序,询问用户有多少人用餐。如果超过8人,就打印一条消息,指出没有空桌;否则指出有空桌。

p1=input("How many people in the dinner?")
p1=int(p1)
if(p1>8):
print("Sorry,There is no empty table.")
else:
print("ok,There is an empty table")


#10的整数倍 :让用户输入一个数字,并指出这个数字是否是10的整数倍。

n1=input("Please input a number")n1=int(n1)if(n1%10==0):print(n1+" is an integer multiple of 10.")else:
print(n1+" is not an integer multiple of 10.")


input函数在python中是一个内建函数,其从标准输入中读入一个字符串,并自动忽略换行符。

也就是说所有形式的输入按字符串处理,如果想要得到其他类型的数据进行强制类型转化。默认情况下没有

提示字符串(prompt string),在给定提示字符串下,会在读入标准输入前标准输出提示字符串。如果遇

文件结束符(end of file)会触发一个EOFError。



到此这篇关于“python中的input函数是什么?”的文章就介绍到这了,感谢各位的阅读,更多相关python中的input函数是什么?内容,欢迎关注群英网络资讯频道,小编将为大家输出更多高质量的实用文章!

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。

标签: python
相关信息推荐
2022-09-21 09:30:54 
摘要:这篇文章主要给大家介绍了关于php+ffmpeg如何获取视频缩略图、视频分辨率等相关信息的相关资料,文中通过实例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
2022-08-06 17:57:15 
摘要:go语言中有两种字符类型:1、byte型,也叫uint8类型,代表了ASCII码的一个字符;2、rune类型,代表一个UTF-8字符,当需要处理中文、日文或者其他复合字符时,则需要用到rune类型。rune类型等价于int32类型。
2022-05-12 11:16:09 
摘要:这篇文章主要介绍了深入理解php底层之php生命周期,对php底层感兴趣的同学,可以参考一下
云活动
推荐内容
热门关键词
热门信息
群英网络助力开启安全的云计算之旅
立即注册,领取新人大礼包
  • 联系我们
  • 24小时售后:4006784567
  • 24小时TEL :0668-2555666
  • 售前咨询TEL:400-678-4567

  • 官方微信

    官方微信
Copyright  ©  QY  Network  Company  Ltd. All  Rights  Reserved. 2003-2019  群英网络  版权所有   茂名市群英网络有限公司
增值电信经营许可证 : B1.B2-20140078   粤ICP备09006778号
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 或 0668-2555555
微信公众号
返回顶部
返回顶部 返回顶部