对于Python来说,一切皆对象。包括数字、字符串、列表等,对象是由类来创建的,那对象的一个优点就是可以使用其创建类中所定义的各种方法。

查看对象/方法

1)可以在命令行中直接查看,如下:

>>> a='I am a string'
>>> type(a)
<class 'str'>

使用type() 可以查看一个变量(对象)的类,找到类后,可以使用dir()来查询里面的方法:

>>> dir(str)
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>>

也可以使用 help()来查询一个类或者方法的详细说明:

help(str)

help(str.upper)

2)当然,也可以在IDE中去查看,也会比较方便。

变量(variable)命名

1 变量名只能包含以下字符:
• 小写字母(a~z)
• 大写字母(A~Z)
• 数字(0~9)
• 下划线(_)
2 名字不允许以数字开头。

3 变量名不能使用python中保留的关键字,如下:

False class finally is return
None continue for lambda try
True def from nonlocal while
and del global not with
as elif if or yield
assert else import pass
break except in raise

python中的基础数据类型以及相关的方法。

数字

在Python中,数字有int和float类型(long在3.x版本中已经被合并为int).

在Python 2 里,一个int 型包含32 位,可以存储从-2 147 483 648 到2 147 483 647 的整数。
一个long 型会占用更多的空间:64 位,可以存储从-9 223 372 036 854 775 808 到9 223 372 036 854 775 807 的整数。
到了Python 3,long 类型已不复存在,而int 类型变为可以存储任意大小的整数,甚至超过64 位。

对于数字来说,它们可以使用基本的数学运算,如:

>>> 5+3       # 加法
8
>>> 0.8*4 # 乘法
3.2
>>> 2**5 # 幂运算
32
>>> 5/2 # 除法
2.5
>>> 5//2 # 商取整
2
>>> 9%2 # 模运算
1

具体来看,

int 类中提供的常用方法有(float和int大多数比较类似):

 abs()   # 求绝对值
>>> abs(-3)
3 __add__(self, *args, **kwargs): # 加法,
>>> a=3
>>> a.__add__(1)
4 __and__(self, *args, **kwargs): # 等同于与运算
>>> a=3
>>> a.__and__(2)
2 __bool__(self, *args, **kwargs): # 返回布尔值
>>> a.__bool__()
True __divmod__(self, *args, **kwargs): # 返回商和余数
>>> b=9
>>> b.__divmod__(7)
(1, 2) __eq__(self, *args, **kwargs): # 判断是否相等
>>> b=9
>>> a=3
>>> b.__eq__(a)
False __float__(self, *args, **kwargs): # 转换为浮点数
>>> b
9
>>> float(b)
9.0 __floordiv__(self, *args, **kwargs): # 等同于 // 运算 __ge__(self, *args, **kwargs): # 判断是否大于等于
>>> a
3
>>> b
9
>>> b.__ge__(a)
True __gt__(self, *args, **kwargs): # 判断是否大于
>>> a
3
>>> b
9
>>> b.__gt__(a)
True __le__(self, *args, **kwargs): # 判断是否小于
>>> a
3
>>> b
9
>>> b.__le__(a)
False __lshift__(self, *args, **kwargs): # 按位左移,相当于翻倍
>>> b
9
>>> b.__lshift__(1)
18 __lt__(self, *args, **kwargs): # 判断是否小于 __mod__(self, *args, **kwargs): # 取模运算,等同于 % __mul__(self, *args, **kwargs): # 乘法运算,等同于 * __neg__(self, *args, **kwargs): # 取负值
>>> b.__neg__()
-9 __ne__(self, *args, **kwargs): # 判断是否不相等 __or__(self, *args, **kwargs): # 相当于 or __pos__(self, *args, **kwargs): # 取正值 __pow__(self, *args, **kwargs): # 幂运算,相当于 ** __round__(self, *args, **kwargs): # Rounding an Integral returns itself.
>>> c.__round__()
6 __sizeof__(self, *args, **kwargs): #
""" Returns size in memory, in bytes """ __str__(self, *args, **kwargs): # 转换成字符串
""" Return str(self). """ __trunc__(self, *args, **kwargs): #
""" Truncating an Integral returns itself. """ __xor__(self, *args, **kwargs): # 按位异或运算,相当于 ^

int常用方法

字符串(str)

在字符串str类中,常用的方法有:

 capitalize(self): # 首字母大写
>>> str1="this is a string"
>>> str1.capitalize()
'This is a string' casefold(self): # 大写字母小写
>>> str2="This Is A String"
>>> str2.casefold()
'this is a string' center(self, width, fillchar=None): # 字符串居中,可以填充空白字符
>>> str3=“center”
>>> str3.center(18,'*')
'******center******' count(self, sub, start=None, end=None): # 计算某字符或者字符串出现的次数
>>> str3.count('ce')
1 encode(self, encoding='utf-8', errors='strict'): # 用于字符串编码 endswith(self, suffix, start=None, end=None): # 判断是否以xx结尾
>>> str3
'center'
>>> str3.endswith('er')
True expandtabs(self, tabsize=8): # 把字符串中的tab转化为空格,默认8个空格 find(self, sub, start=None, end=None): # 找子序列,并返回所在位置,找不到返回-1 >>> str3.find('er')
4
>>> str3.find('nr')
-1 format(*args, **kwargs): # 用于字符串格式化
>>> '{0}, is a {1}'.format('This','string')
'This, is a string' index(self, sub, start=None, end=None): # 同find,但是找不到的话会报错
>>> str3
'center'
>>> str3.index('nr')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found isalnum(self): # 判断字符串是否是字母和数字的结合
>>> a=''
>>> a.isalnum()
False isalpha(self): # 判断字符串是否都是字母
>>> str3
'center'
>>> str3.isalpha()
True isdecimal(self): # Return True if there are only decimal characters in S, isdigit(self): # 判断是否都是数字
>>> a=''
>>> a.isdigit()
True isidentifier(self): # 判断是否是关键字
>>> a='123def'
>>> a.isidentifier()
False
>>> a='def'
>>> a.isidentifier()
True islower(self): # 判断是否都是小写字母 isnumeric(self): # 判断是否都是数字 isspace(self): # 判断是否都是空格 istitle(self): # 判断是否是title,即每个单词首字母大写
>>> a='This Is A String'
>>> a.istitle()
True isupper(self): # 判断是否都是大写字母 join(self, iterable): # 用来做拼接
>>> a
'This Is A String'
>>> b='*'
>>> b.join(a)
'T*h*i*s* *I*s* *A* *S*t*r*i*n*g' ljust(self, width, fillchar=None): # 字符串靠左,可以指定填充字符
>>> str4='left'
>>> str4.ljust(20,'*')
'left****************' lower(self): # 大写字母全部转换成小写 lstrip(self, chars=None): # 字符串左边去除空格或者指定的字符串 partition(self, sep): # 用来做分割
S.partition(sep) -> (head, sep, tail)
Search for the separator sep in S, and return the part before it,
the separator itself, and the part after it. If the separator is not
found, return S and two empty strings. replace(self, old, new, count=None): # 替换字符或者字符串
>>> a
'This Is A String'
>>> a.replace('ring','o')
'This Is A Sto' rfind(self, sub, start=None, end=None): #
"""
S.rfind(sub[, start[, end]]) -> int Return the highest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation. Return -1 on failure.
"""
return 0 rindex(self, sub, start=None, end=None): #
"""
S.rindex(sub[, start[, end]]) -> int Like S.rfind() but raise ValueError when the substring is not found.
"""
return 0 rjust(self, width, fillchar=None): # 字符串右移,可以指定填充字符
"""
S.rjust(width[, fillchar]) -> str Return S right-justified in a string of length width. Padding is
done using the specified fill character (default is a space).
"""
return "" rpartition(self, sep): #
"""
S.rpartition(sep) -> (head, sep, tail) Search for the separator sep in S, starting at the end of S, and return
the part before it, the separator itself, and the part after it. If the
separator is not found, return two empty strings and S.
"""
rstrip(self, chars=None): # 字符串右侧删除空格或指定字符串 split(self, sep=None, maxsplit=-1): 指定分隔符分割字符串 startswith(self, prefix, start=None, end=None): # 判断字符串是否以指定字符开头 strip(self, chars=None): # 字符串两边删除空格或者指定字符串 swapcase(self): # 大写转小写,小写转大写 title(self): # 设置title,即每个单词首字母大写
>>> a='this is a string'
>>> a.title()
'This Is A String' upper(self): # 转换成大写字母 zfill(self, width): # 用0来填充字符串没有填充的位置 __add__(self, *args, **kwargs): # 字符串拼接 __eq__(self, *args, **kwargs): # 判断字符串是否相等 __len__(self, *args, **kwargs): # 获取字符串的长度
>>> a
'this is a string'
>>> len(a)
16 索引操作--字符串可以使用索引来获取相应位置的字符,如: >>> a
'this is a string'
>>> a[-1]
'g'
>>> a[0]
't' 字符串也支持切片操作,如: >>> a[:5]
'this '
>>> a[7:]
' a string'
>>>

字符串常用方法

注意:字符串的拼接最好不要使用‘+’,这样会浪费不必要的空间。

使用* 可以进行字符串复制,如下:

>>> 'ab'*4
'abababab'

字符串切片操作请参考这里

列表(list)

列表是一组有序的数据集合。对列表可以进行遍历,增删改查等操作。

list类中提供了如下常用的方法:

 append(self, p_object): # 在列表尾部新增一个元素
>>> li
[1, 2, 3, 4]
>>> li.append(5)
>>> li
[1, 2, 3, 4, 5] clear(self): # 清空一个列表
>>> li
[1, 2, 3, 4, 5]
>>> li.clear()
>>> li
[] copy(self): # 浅拷贝一个列表
>>> li=[1,2,3,4]
>>> li2=li.copy()
>>> li2
[1, 2, 3, 4] count(self, value): # 计算某个元素出现的次数
>>> li2
[1, 2, 3, 4, 2]
>>> li2.count(2)
2 extend(self, iterable): # 扩展一个列表
>>> li3
['a', 'b', 'c']
>>> li
[1, 2, 3, 4]
>>> li.extend(li3)
>>> li
[1, 2, 3, 4, 'a', 'b', 'c'] index(self, value, start=None, stop=None): # 获取元素的index值
>>> li
[1, 2, 3, 4, 'a', 'b', 'c']
>>> li.index('b')
5 insert(self, index, p_object): # 在index位置前面插入一个元素
>>> li
[1, 2, 3, 4, 'a', 'b', 'c']
>>> li.insert(4,'d')
>>> li
[1, 2, 3, 4, 'd', 'a', 'b', 'c'] pop(self, index=None): # 删除一个元素,可以指定index值
>>> li
[1, 2, 3, 4, 'd', 'a', 'b', 'c']
>>> li.pop(4)
'd'
>>> li
[1, 2, 3, 4, 'a', 'b', 'c'] remove(self, value): # 删除一个元素
>>> li
[1, 2, 3, 4, 'a', 'b', 'c']
>>> li.remove('a')
>>> li
[1, 2, 3, 4, 'b', 'c'] reverse(self): # 反转一个列表
>>> li
[1, 2, 3, 4, 'b', 'c']
>>> li.reverse()
>>> li
['c', 'b', 4, 3, 2, 1] sort(self, key=None, reverse=False): # 对列表进行排序
>>> li
[4, 3, 2, 1]
>>> li.sort()
>>> li
[1, 2, 3, 4] len(): #计算列表的长度
>>> li
[1, 2, 3, 4]
>>>
>>>
>>> len(li)
4

列表常用方法

列表可以使用index值来查询元素,但是使用index时要注意边界检查,如:

>>> li
[1, 2, 3, 4]
>>> li[3]
4
>>> li[5]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range

列表解析

会通过对序列中每一项运行一个表达式来生成一个新的列表,字典或者集合

>>> M=[[1,2,3],[4,5,6],[7,8,9]]
>>> col2= [row[1] for row in M]
>>> col2
[2, 5, 8]

>>> {x*2 for x in [1,2,3,4]}
{8, 2, 4, 6}

>>> {x:(x/2) for x in [1,2,3,4]}
{1: 0.5, 2: 1.0, 3: 1.5, 4: 2.0}

复制列表

通过下面任意一种方法,都可以将一个列表的值复制到另一个新的列表中,复制后改变原列表的值不会影响到新列表的值:
• 列表copy() 函数
• list() 转换函数
• 列表分片[:]

元组(tuple)

元组类似于列表,但是它具有不可变性。并且相比起列表,元组占用的空间会小一点。

>>> t1=(1,2,3,4)
>>> t1
(1, 2, 3, 4)
>>> t1[2]
3
>>> t1[2]=5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment

tuple类中的常用操作,有:

count(self, value): # 返回某个元素出现的次数
>>> t1
(1, 2, 3, 4)
>>> t1.count(4)
1 index(self, value, start=None, stop=None): # 查找某个元素的index值
>>> t1
(1, 2, 3, 4)
>>> t1.index(2)
1

元组的元素也可以是元组,字典或者列表

>>> t1=([1,2],(3,4),{'k1':'v1'})
>>> t1
([1, 2], (3, 4), {'k1': 'v1'})

字典(dict)

它是一系列‘键:值’对的合集。

clear(self): # 清空一个字典
>>> dic
{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
>>> dic.clear()
>>> dic
{} copy(self): # 浅拷贝一个字典
>>> dic
{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
>>> dic2=dic.copy()
>>> dic2
{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'} fromkeys(*args, **kwargs): # 拿到key,指定value,生成一个新的字典
>>> key=[1,2,3,4]
>>> newdic={}
>>> newdic=newdic.fromkeys(key,'value')
>>> newdic
{1: 'value', 2: 'value', 3: 'value', 4: 'value'} get(self, k, d=None): # 给定key去获取相应的value,,如果key不存在,默认返回一个None,或者指定的值
>>> dic
{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
>>> dic.get('k1')
'v1'
>>> dic.get('k4')
>>> dic.get('k5',9)
9
items(self): # 获取字典的键值对
>>> dic
{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
>>> dic.items()
dict_items([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3')]) keys(self): # 获取字典的key值
>>> dic
{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
>>> dic.keys()
dict_keys(['k1', 'k2', 'k3']) pop(self, k, d=None): # 删除一个值根据指定的key,如果key没有找到,返回指定的值
>>> dic
{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
>>> dic.pop('k5')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'k5'
>>> dic.pop('k5',0)
0 popitem(self): # 随机删除字典内一个键值对 setdefault(self, k, d=None): # 对指定的key设置默认值
>>> dic
{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
>>> dic.setdefault('k5','v5')
'v5'
>>> dic
{'k5': 'v5', 'k1': 'v1', 'k2': 'v2', 'k3': 'v3'} update(self, E=None, **F): # 更新字典
>>> dic
{'k5': 'v5', 'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
>>> dic3={'key':'value'}
>>> dic3
{'key': 'value'}
>>> dic.update(dic3)
>>> dic
{'k5': 'v5', 'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'key': 'value'}
values(self): # 获取字典的值
>>> dic
{'k5': 'v5', 'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'key': 'value'}
>>> dic.values()
dict_values(['v5', 'v1', 'v2', 'v3', 'value'])

在Python 3.x版本中,字典的keys,values和items返回的都是视图对象,如果想对其进行列表的操作,需要先转化为列表才行。

另外,3.x中取消了has_key方法(用来测试key是否存在),同样的功能可以使用in来实现:

>>> dic
{'k5': 'v5', 'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'key': 'value'}
>>> 'k5' in dic
True

集合(set)

无序,并且不允许内部元素重合。

创建集合

>>> empty_set = set()
>>> empty_set
set()
>>> even_numbers = {0, 2, 4, 6, 8}
>>> even_numbers
{0, 8, 2, 4, 6}
>>> odd_numbers = {1, 3, 5, 7, 9}
>>> odd_numbers
{9, 3, 1, 5, 7}
>>> a = {1,1,2,3,4}
>>> a
{1, 2, 3, 4}

可以使用set()将列表和元组转换为集合。如果尝试用set()转换字典的话,转换后的集合只包含字典的key。

交集运算 &

>>> a={1,2,3,4}
>>> b={3,4,5,6,7}
>>> a&b
{3, 4}
>>> a.intersection(b)
{3, 4}

并集运算 |

>>> a
{1, 2, 3, 4}
>>> b
{3, 4, 5, 6, 7}
>>> a|b
{1, 2, 3, 4, 5, 6, 7}
>>> a.union(b)
{1, 2, 3, 4, 5, 6, 7}

差集运算 |

>>> a
{1, 2, 3, 4}
>>> b
{3, 4, 5, 6, 7}
>>> a-b
{1, 2}
>>> b-a
{5, 6, 7}
>>> a.difference(b)
{1, 2}
>>> b.difference(a)
{5, 6, 7}

其他集合运算

使用^ 或者symmetric_difference() 可以获得两个集合的异或集(仅在两个集合中出现一次):

>>> a
{1, 2, 3, 4}
>>> b
{3, 4, 5, 6, 7}
>>> a^b
{1, 2, 5, 6, 7}
>>> a.symmetric_difference(b)
{1, 2, 5, 6, 7}

使用<= 或者issubset() 可以判断一个集合是否是另一个集合的子集(第一个集合的所有元素都出现在第二个集合中):

>>> a
{1, 2, 3, 4}
>>> b
{3, 4, 5, 6, 7}
>>> c
{1, 2, 3}
>>> a<=b
False
>>> c<=b
False
>>> c<=a
True
>>> c.issubset(a)
True

当第二个集合包含所有第一个集合的元素,且仍包含其他元素时,我们称第一个集合为第二个集合的真子集。使用< 可以进行判断

超集与子集正好相反(第二个集合的所有元素都出现在第一个集合中),使用>= 或者issuperset() 可以进行判断:

>>> a
{1, 2, 3, 4}
>>> b
{3, 4, 5, 6, 7}
>>> c
{1, 2, 3}
>>> b>=a
False
>>> a>=c
True
>>> a.issuperset(c)
True
>>> a.issuperset(a)
True

数据格式化

数据格式化的内容点这里

Python学习之--数据基础的更多相关文章

  1. python学习日记(基础数据类型及其方法01)

    数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print ...

  2. Python学习day12-函数基础(2)

    <!doctype html>day12博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { pos ...

  3. Python学习课程零基础学Python

    python学习课程,零基础Python初学者应该怎么去学习Python语言编程?python学习路线这里了解一下吧.想python学习课程?学习路线网免费下载海量python教程,上班族也能在家自学 ...

  4. [Python] Python 学习 - 可视化数据操作(一)

    Python 学习 - 可视化数据操作(一) GitHub:https://github.com/liqingwen2015/my_data_view 目录 折线图 散点图 随机漫步 骰子点数概率 文 ...

  5. Python学习day16-模块基础

    <!doctype html>day16 - 博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { ...

  6. Python学习day11-函数基础(1)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  7. Python学习笔记之基础篇(-)python介绍与安装

    Python学习笔记之基础篇(-)初识python Python的理念:崇尚优美.清晰.简单,是一个优秀并广泛使用的语言. python的历史: 1989年,为了打发圣诞节假期,作者Guido开始写P ...

  8. Python学习总结之一 -- 基础篇

    Python学习第一篇 一:写在前面 啊,最近我的新博客一直都没有更新学习内容了,只是最近一直都在忙着寻找实习机会(或许这只是一个借口,真实原因是我太懒惰了,改改改!).终于今天又投递了几个新的实习职 ...

  9. python学习笔记之基础数据和控制

    注释: 单行注释 # 多行注释'''    ''' 注意:当注释中有汉字时需要在python文件的第一行添加如下内容之一:#coding:gbk或#coding:utf-8或##-*- coding ...

随机推荐

  1. SQL链接EXCEL操作

    Sub CopyData_5() Set Cnn = CreateObject("ADODB.Connection")With Cnn.Provider = "micro ...

  2. VS环境下,DEV插件的ComboBoxEdit控件最简单的数据源绑定和获取方法

    使用 ComboBoxEdit 控件绑定key/value值: 因为 ComboBoxEdit 没有 DataSource 属性,所以不能直接绑定数据源,只能一项一项的添加. 首先创建一个类ListI ...

  3. 什么是 Hexo?

    Hexo   文档 欢迎使用 Hexo,本文档将帮助您快速上手.如果您在使用过程中遇到问题,请查看 问题解答 中的解答,或者在 GitHub.Google Group 上提问. 什么是 Hexo? H ...

  4. [Usaco2005 Dec]Cleaning Shifts

    [Usaco2005 Dec]Cleaning Shifts 给出n段区间,左右端点分别为\(l_i,r_i\),以及选取这段区间的费用\(c_i\),现在要选出若干个区间,使其完全覆盖区间\([m, ...

  5. thinkphp DEFINED标签

    DEFINED标签用于判断某个常量是否有定义,用法如下: 大理石平台检验标准 <defined name="NAME"> NAME常量已经定义 </defined ...

  6. 暑假集训test-8-14~8-15

    我不想写博客辣. 拖了三天的一起写,结果就是写不下去了...果然应该改一道写一道么.. 题面题解代码也懒得往博客上放了,屯U盘里了... 因为太菜还有两道没有改. 题解外的一些参考: lyc大佬的进程 ...

  7. 详解JDBC与Hibernate区别

    详解JDBC与Hibernate区别 引用地址:http://www.cnblogs.com/JemBai/archive/2011/04/13/2014940.html 刚开始学习JAVA时,认为H ...

  8. import socketserver 模块 (27-03)

    使用socketserver实现并发聊天 服务端可以比喻做一部电话. ("127.0.0.1", 8000) 比喻做服务端的一个号码. 1,server.py import soc ...

  9. Django杂篇(1)

    目录 Django杂篇(1) bulk_create Pagination 创建多对多表关系的常用方法 form校验组件的应用 渲染页面 展示错误信息 校验数据 常用字段 Django杂篇(1) 这里 ...

  10. 窥探C语言程序的编译、链接与.h文件

    概述 C语言程序从源文件经过编译.链接生成可执行文件.那么编译与链接分别做了什么? 开发中为什么使用.h编写函数的声明?接下来使用案例说清楚为什么这样编写代码. C语言程序的编译和链接 C语言程序从源 ...