We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python3 六个标准的数据类型。 四种数据结构:元组、列表、集合、字典。
通过 type() 函数查看数据类型:
>>> print(type(1)) <class 'int'> >>> import math >>> print(type(math.pi)) <class 'float'> >>> print(type(True and False)) <class 'bool'> >>> print(type(complex(1, 2))) <class 'complex'>
>>> print(type('1')) <class 'str'>
>>> print(type((1,2,3))) <class 'tuple'>
>>> print(type([1,2,3])) <class 'list'>
>>> print(type({1,2,3})) <class 'set'>
>>> print(type({'a':1,'b':2,'c':"123"})) <class 'dict'>
Python3 支持 int、float、bool、complex(复数)
/
//
'
"
\
r
""" """
''' '''
()
>>> letters = ('a','b','c','d','e','f','g') >>> letters[0] 'a'
[]
len()
>>> Weekday = ['Monday','Tuesday','Wednesday','Thursday','Friday'] >>> print(Weekday[0]) Monday
{}
set()
>>> a_set = {1,2,3,4} >>> a_set.add(5) >>> print(a_set) {1, 2, 3, 4, 5} >>> a_set.discard(5) >>> print(a_set) {1, 2, 3, 4}
https://stackoverflow.com/questions/2831212/python-sets-vs-lists :
>>> NASDAQ_code = { ... 'BIDU':'Baidu', ... 'SINA':'Sina', ... 'YOKU':'Youku' ... } >>> print(NASDAQ_code) {'BIDU': 'Baidu', 'YOKU': 'Youku', 'SINA': 'Sina'}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
通过 type() 函数查看数据类型:
Number(数字)
/
总是返回一个浮点数,要获取整数使用//
操作符。在混合计算时, Python 会把整型转换成为浮点数。String(字符串)
'
或双引号"
括起来,同时使用反斜杠\
转义特殊字符。\
转义特殊字符,如果你不想让反斜杠发生转义,可以在字符串前面添加一个r
,表示原始字符串。\
可以作为续行符,表示下一行是上一行的延续。也可以使用""" """
或者''' '''
跨越多行。Tuple(元组)
()
里,元素之间用逗号隔开。List(列表)(类似 Java List 集合接口)
[]
之间、用逗号分隔开的元素列表。len()
返回字符串长度。Sets(集合)(类似 Java Set 集合接口)
{}
或者set()
函数创建集合,注意:创建一个空集合必须用set()
而不是{}
,因为{}
是用来创建一个空字典。https://stackoverflow.com/questions/2831212/python-sets-vs-lists :
Dictionary(字典)(类似 Java Map 集合接口)
{}
。The text was updated successfully, but these errors were encountered: