龙源期刊网
http://www.qikan.com.cn
基于
Python
的动态语言特点探讨
作者:谢生锋
来源:《电脑知识与技术》
2017
年第
33
期
摘要:
Python
是一种面向对象的解释型计算机程序设计语言,也是一种功能强大的通用型
语言,该语法简洁清晰,具有丰富和强大的标准库和扩展库,成熟且稳定。该文主要探讨了
Python
编程语言的特点,并和
C
语言在相关语法上做了对比。
关键词:
Python
;动态;
C
语言
中图分类号:
TP311
文献标识码:
A
文章编号:
1009-3044
(
2017
)
33-0131-02
Abstract
:
Python is an object-oriented and interpreted computer programming language
,
also
is a powerful universal language
,
its grammar is simple and clear
,
with the rich and powerful of
standard library and extension library
,
and it’s mature and st
able. This paper mainly discusses the
characteristics of Python programming language
,
and makes a comparison with C language in
related grammar.
Key words
:
Python
;
dynamic
;
C language
1
背景
由于
Python
编程语言的语法灵活,并且有些语法和
C
语言是完全不同的,笔者结合自身
的教学经历,在教学过程中发现学生在学习完
C
程序设计课程后,再学习
Python
程序设计,
很容易把两种语言的语法相混淆,为了便于学生更好的理解
Python
语言的特点,把易难、易
混淆的语法进行讲解
[1]
。
2 Python
语言的特点分析
2.1
变量的类型
在
Python
语言中,声明变量不需要指明变量的数据类型,而是由
Python
解释器根据赋值
运算符后面的常量类型来推断变量的类型,如果常量是一个整数,那么变量的类型就是整型。
并且变量的类型可以动态变化,在程序运行时可以指向不同数据类型的常量,这体现出
Python
语言的动态性。
这一点和
C
语言截然不同,
C
语言声明变量时,首先要声明变量的数据类
型,比如
int
、
float
、
double
或
char
等
[2]
。实例代码如下:
x = 5
(
type
(
x
))
#
输出