1、python3→help()→keywords
False | def | if | raise |
---|---|---|---|
Trure | del | import | return |
None | elif | in | try |
and | else | is | while |
as | except | lambda | with |
asssert | finally | nonlocal | yield |
break | for | not | |
class | from | or | |
continue | global | pass |
2、python中不需要为变量指定类型(自动识别)
python可以操作字符串(用引号括起来 )
3、Python3 怎样从键盘读取输入
通常情况下,Python 的代码中是不需要从键盘读取输入的。不过我们还是可以在 Python 中使用函数 input() 来做到这一点,input() 有一个用于打印在屏幕上的可选字符串参数,返回用户输入的字符串。
如何理解input()
我们设 y = input(“对用户的提示信息”)
则 y 是用户键入的字符
自动填入程序代码中
number = int(input("Enter an integer: "))
用户看到的代码界面是这样的:
Enter an integer:(用户键入与提示信息相符的字符,假设键入390)
返回代码程序:
number = int(390)
就这么理解吧:
y=input("Enter an integer: ")
是一个函数
"Enter an integer: " = 函数的定义域
y = 函数的值域
4、Python3 字符串的格式化
print("Year {} Rs. {:.2f}".format(year, value))
"Year {} Rs. {:.2f}".format(year, value)
称为字符串格式化,大括号和其中的字符会被替换成传入str.format()
的参数,也即 year 和 value。其中 {:.2f} 的意思是替换为 2 位精度的浮点数。
例如:
Year 1 Rs. 11400.00
Year 2 Rs. 12996.00
Year 3 Rs. 14815.44
Year 4 Rs. 16889.60
Year 5 Rs. 19254.15
5、元组封装和拆封
data = ("Linux", "China", "Python")# 元组封装
name, country, language = data# 元组拆分
name
'Linux'
country
'China'
language
'Python'
PS:学习一定要及时记录反馈坚持就是胜利!!