还记得我们上节课学习的print
函数吗?其实它还可以连续输出几个序列, 我们将在本节看到。
本节主要枚举了Python中常用的数据类型(整点/浮点数字, 字符串, 布尔), 合理的变量命名规则(数字字母下划线,且不以数字开头)以及不常见的运算符(布尔:and/or/not; 整除://; 取余:%; 乘方:**)。
Syntax.py
# -*- coding: utf-8 -*-
# data-type
typelist = [
1, -1, 0, 1.23e5, -1.23e-5,
0xff00,
'abc', "I'm ok!", 'I\'m \"ok\"!', '''This is \
a multiline \
string''',
True, False, 0 and 1, 0 or 1, not 1,
None,
0 == None,
]
# variables
_numlist = typelist[:6]
strlist = typelist[7:10]
strlist_1 = strlist[1]
bool_list_all = typelist[11:12]
truetests = typelist[13:]
# Constants
PI = 3.141592653
# operators
a = 10
b = 3
print(
'a=', a,
'\nb=', b,
'\na/b=', a / b,
'\na//b=', a // b,
'\na%b=', a % b,
'\na**b=', a**b
)
print('All types of data:\n', typelist)
print('\tNumber types:\n', _numlist)
print('\tString types:\n', strlist)
print('\tSecond elements of string variable:\n', strlist_1)
print('\tBool types:\n', bool_list_all)
print('\tBool operator test:\n', truetests)
print('Constant Pi:\n', PI)