Python——8.基础语法

1.关键字
In [21]: import keyword                                                                                                             
In [22]: keyword.iskeyword                                                                                                             
Out[22]: <function frozenset.__contains__>
In [23]: keyword.kwlist                                                                                                                
Out[23]: 
['False',
 'None',
 'True',
 'and',
...............
2.注释

单行注释#,多行注释可以用多个 # 号、 ‘’’ 和 “”"。
空语句pass
语句换行

total = item_one + \
        item_two + \
        item_three

[], {}, 或 () 中的多行语句换行不需要反斜杠。

3.变量声明

赋值即使用,赋值以后该变量才会被创建。变量没有类型. 分配内存后才有。

4.数据类型

Python3 中有六个标准的数据类型:
不可变数据:Number、String、Tuple。
可变数据:List、Set、Dictionary。
Number:int、bool、float、complex (如complex(1,2))

内置的 type() 函数和 isinstance() 可以用来查询变量所指的对象类型。

5.type()
In [4]: help(type)
Help on class type in module builtins:
class type(object)
 |  type(object_or_name, bases, dict)
 |  type(object) -> the object's type
 |  type(name, bases, dict) -> a new type
 |  
 |  Methods defined here:
 |  
 |  __call__(self, /, *args, **kwargs)
 |      Call self as a function.
................................
6.isinstance()
In [3]: help(isinstance)                                                                                                               
Help on built-in function isinstance in module builtins:

isinstance(obj, class_or_tuple, /)
    Return whether an object is an instance of a class or of a subclass thereof.
    
    A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to
    check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)
    or ...`` etc.
7.del语句
 In [18]: class A: 
    ...:      
    ...:     pass                                                                                                      
In [19]: a=A()                                                                                                                         
In [20]: del a      

————Blueicex 2020/2/22 19:11 blueice1980@126.com

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值