两分钟理解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。
感激各人的浏览,心愿各人收益多多。
本文转自:https://blog.csdn.net/qq_24135817/article/details/79818479
保举教程:《python教程》
以上就是两分钟理解python中的input函数的具体内容,更多请存眷资源魔其它相干文章!
标签: Python python教程 python编程 python使用问题 input函数
抱歉,评论功能暂时关闭!