Day4:Input 输入

在Python 2中raw_input( )将所有输入作为字符串(String)看待,返回字符串类型input( )只接收“数字”的输入,在对待纯数字输入时具有自己的特性,它返回所输入的数字的类型( int, float )

在Python 3中已取消raw_input之函数并把raw_input和input()整合,将所有输入默认为字符串(String)处理,并返回字符串类型。

那让我们来个程序码练习今天的input()函数。

[In]
print ("How old are you?"),
age=input()
print('How much is this?'),
price=input()
result=f"So,you are {age} years olds and this thing is {price} dollars"
#day3学到的字串格式化
#记住前面要f然後两边要加"{}"
result
[Out]
How old are you?
55
How much is this?
55
'So,you are 55 years olds and this thing is 55 dollars'

然後可以在input()函数的括号里面添加提示字,像是这样。

e.g

[In]
age=input("What is your name?")
price=input("How much is this?")
result=f"So,you are {age} years olds and this thing is {price} dollars"
#day3学到的字串格式化
#记住前面要f然後两边要加"{}"
result
[Out]
What is your name? 6
How much is this? 9
'So,you are 6 years olds and this thing is 9 dollars'

今天我的笔记就到这边XD

source:https://ppt.cc/fHC3kx


<<:  ADXL335三轴加速度晶片结合Arduino nano传数据

>>:  【前端 HTML/JSX】在Input框内部加上Icon?除了使用Bootstrap、Semantic或Material-UI之外你还可以这麽做

HERE API Example - 显示 KML 资料

KML (Keyhole Markup Language,锁孔标记语言) 是一种档案格式,用於存储地...

【在厨房想30天的演算法】Day 18 演算法 : 搜寻 search II 指数搜寻、内插搜寻

Aloha!又是我是少女人妻 Uerica!白天楼上常常会施工,钻地板跟敲打的声音总是让人难以忍受,...

[Kata] Clojure - Day 29

Growth of a Population In a small town the populat...

不用Recoil的话,如何自己制作一个 Custom hook 来共享全域变数?

需求 在早前几篇文章,我们介绍了 Recoil 这个 library 来在整个 App 分享全域变数...

AE特效烛火-Day14

六指渊参考范例:https://www.sixvfx.com/ae_combustion 今天练习烛...