python交互解释器
linux shell
python中if语句格式: Python 3.4.3 (default, Nov 28 2017, 16:41:13) [GCC 4.8.4] on linuxType 'help', 'copyright', 'credits' or 'license' for more information.>>> x = 1>>> if x > 0:... print (' x > 0 is True.')... x > 0 is True.>>>
python中if ... else ... 格式:Python 3.4.3 (default, Nov 28 2017, 16:41:13) [GCC 4.8.4] on linuxType 'help', 'copyright', 'credits' or 'license' for more information.>>> x = 1>>> if x > 0 :... print ('x > 0 is True.')... else:... print ('x > 0 is False.')... x > 0 is True.>>>
python中if ... elif ... else格式:Python 3.4.3 (default, Nov 28 2017, 16:41:13) [GCC 4.8.4] on linuxType 'help', 'copyright', 'credits' or 'license' for more information.>>> x = 1>>> if x > 0:... print ('x > 0 is True.')... elif x == 0:... print ('x == 0 is True.')... else:... print ('x < 0 is True.')... x > 0 is True.>>>
注意python中的表达式格式,与其它语言不同,不需要小括号来包裹表达式。