1python面向对象,强or弱类型?语言,解释性语言 运算速度不快
强类型:有人说不允许不同类型相加的是强类型,例如:整形+字符串会报类型错误,是这样吗?
还有人说,是看能否做隐式转换,如果不做强制转换,它的类型就固定了
强制性体现在哪方面? 必须先定义再使用
强弱判断的标准是什么?我也搞不清楚了,如果像python这样类型,重新给a赋值一个其他类型的,它其实就是一个全新的内容,与之前这个名字是什么无关,我觉得这点反应出的是它的动态性,
综合各种说法,我觉得,动态性本身就像是弱类型的一个自带属性一般的存在,你要弱化了类型,就必然有弱化后的优势,而这个优势,就是更自由,更随意,可以动态随心而变。所以基于python是动态的,我现在宁愿理解认为他是弱类型。
动态:不使用显示数据类型声明,且确定一个变量的类型是在第一次给它赋值的时候。
脚本语言:一般是解释性语言,运行代码只需要一个解释器,不需要编译。
>>> 7+"ddd"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> a=3
>>> a="dd"
>>> type(a)
<type 'str'>
>>> a=5
>>> type(a)
<type 'int'>
>>> id(a)
10273032
>>> a="dd"
>>> id(a)
140376160996008
>>> a
'dd'
>>> 1 == True
True
2查看版本 python --version (2.7,3,3.5)
3解释器及其环境--编码注释
#-*-编码:编码-*- 例如 #-*- UTF-8-*- 必须放在首行
例外:放在第二行
#!/usr/bin/env python3
# -*- coding: cp1252 -*-
解释器的操作有点像unix shell:当使用连接到tty设备的标准输入调用时,解释器以交互方式读取和执行命令;当使用文件名参数或文件作为标准输入调用时,解释器从该文件读取和执行脚本
python test.py
python -c
python -m
使用脚本文件时,有时能够运行脚本并随后进入交互模式非常有用。这可以通过在脚本之前传递-i来完成。
参数传递
当解释器知道时,脚本名和其后的其他参数将变为字符串列表,并分配给sys模块中的argv变量
当脚本名被指定为“-”(表示标准输入)时,sys.argv[0]被设置为“-”。
使用-c命令时,sys.argv[0]设置为“-c”。
使用-m模块时,sys.argv[0]设置为所找到模块的全名。
在-c命令或-m模块之后找到的选项不会被python解释器的选项处理所使用,而是留在sys.argv中供命令或模块处理。
lsx@sx-Inspiron-N301Z:~$ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.argv[0]
''
>>>