默认情况下,python以UTF-8编码,所有的字符串都是Unicode字符串,可以为代码定义不同的的编码。
#coding:UTF-8 #OR #-*- coding:UTF-8 -*-
保留字及为关键字,不能作为任何标识符名称。查看当前版本所有关键字:keyword模块
1 import keyword #导入keyword模块 2 keyword.kwlist
[‘False‘, ‘None‘, ‘True‘, ‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘la
单行注释:代码中以#开头的行即为注释,程序在执行时不会执行该行
多行注释:"""多行注释""" or ‘‘‘多行注释‘‘
#这是一个注释 ‘‘‘ 这是第二个注释 ‘‘‘ """ 这是第3个注释 """
python中有数据类型:布尔型、整型、长整型、浮点型、字符串、列表、元组、字典、日期
In [4]: bool(True) Out[4]: True In [5]: bool(False) Out[5]: False In [6]: bool(0) Out[6]: False In [8]: bool([]) #空列表 Out[8]: False In [9]: bool(()) #空元组 Out[9]: False In [10]: bool({}) #空字典 Out[10]: False In [12]: bool(1) Out[12]: True .................
#type():查看数据类型 In [13]: type("hello world") Out[13]: str In [14]: type("123") Out[14]: str
标准输出,print()默认输出是换行的,如果要实现不换行,需在末尾加上 end=""
>>>print("hello world!",end="","hello python!") #不换行输出 >>>hello world! hello python!
原文:http://www.cnblogs.com/yanglang/p/7606703.html