A byte of python :20天python基础---lesson1

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]
''
>>>

 

this is a book about python. it was written by Swaroop C H.its name is "a byte of python". Table of Contents Preface Who This Book Is For History Lesson Status of the book Official Website License Terms Using the interpreter prompt Choosing an Editor Using a Source File Output How It Works Executable Python programs Getting Help Summary 4. The Basics Literal Constants Numbers Strings Variables Identifier Naming Data Types Objects Output How It Works Logical and Physical Lines Indentation Summary 5. Operators and Expressions Introduction Operators Operator Precedence Order of Evaluation Associativity Expressions Using Expressions Summary 6. Control Flow Introduction The if statement ivUsing the if statement How It Works The while statement Using the while statement The for loop Using the for statement Using the break statement The continue statement Using the continue statement Summary 7. Functions Introduction Defining a Function Function Parameters Using Function Parameters Local Variables Using Local Variables Using the global statement Default Argument Values Using Default Argument Values Keyword Arguments Using Keyword Arguments The return statement Using the literal statement DocStrings Using DocStrings Summary 8. Modules Introduction Using the sys module Byte-compiled .pyc files The from..import statement A module's __name__ Using a module's __name__ Making your own Modules Creating your own Modules from..import The dir() function Using the dir function Summary 9. Data Structures Introduction List Quick introduction to Objects and Classes Using Lists Tuple Using Tuples Tuples and the print statement Dictionary Using Dictionaries Sequences Using Sequences References Objects and References More about Strings String Methods Summary 10. Problem Solving - Writing a Python Script The Problem The Solution First Version Second Version Third Version Fourth Version More Refinements The Software Development Process Summary 11. Object-Oriented Programming Introduction The self Classes Creating a Class object Methods Using Object Methds The __init__ method Using the __init__ method Class and Object Variables Using Class and Object Variables Inheritance Using Inheritance Summary 12. Input/Output Files Using file Pickle Pickling and Unpickling Summary 13. Exceptions Errors Try..Except Handling Exceptions Raising Exceptions How To Raise Exceptions Try..Finally Using Finally Summary 14. The Python Standard Library Introduction The sys module Command Line Arguments More sys The os module Summary 15. More Python Special Methods Single Statement Blocks List Comprehension Using List Comprehensions Receiving Tuples and Lists in Functions Lambda Forms Using Lambda Forms The exec and eval statements The assert statement The repr function Summary 16. What Next? Graphical Software Summary of GUI Tools Explore More Summary A. Free/Libré and Open Source Software (FLOSS) B. About Colophon About the Author C. Revision History Timestamp
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值