Hello,大家好,今天我们来了解下Python代码里的重量级选手:内建函数
了解函数
函数,可以理解为带括号‘()’的操作符。比如说print()函数。他可以接收一个值,并输出。这就是个很典型的例子。但,这些都是在编写程序已经加入好的程序包,万一用户要自己建一个函数呢?于是,就来了一个内建函数
什么叫内建函数
内建函数,顾名思义,就是由用户自己建造一个函数。这个函数不会受限制,可以包含数字,单词,大写字母等。这个函数将会在运行台显示。而且,你也可以用int()函数将字符串转换为整型,这样你就可以在运行台输入了。内建函数分为很多种,比如说int,input等
代码实例
>>> raw_input_A = raw_input("raw_input: ")
raw_input: abc >>> input_A = input("Input: ")
Input: abc
Traceback(most recent call last):
File "<pyshell#1>", line 1, in < module >
input_A = input("Input: ")
File "<string>", line 1, in < module >
NameError: name 'abc'
is not defined
>>> input_A = input("Input: ")
Input: "abc" >>>
>>> raw_input_B = raw_input("raw_input: ")
raw_input: 123 >>> type(raw_input_B) < type 'str' >
>>> input_B = input("input: ")
input: 123 >>> type(input_B) < type 'int' >
注释:这里的代码是属于简单的,后续的其他内建函数的代码我会慢慢出。
好了,今天就讲到这里,关注我,带你玩转编程