使用Python进行测试的条件语句与我们编写的其他编程语言相似,在采取任何决定之前,if和else语句将根据某些条件获得所需的结果。
如何在Python示例中使用条件语句,我们使用的是Mint操作系统,该操作系统的Python版本为2.7.6,Python版本为3.4.0,但条件语句不依赖于操作系统,因此我们可以使用任何OS。此条件语句也适用于早期的Python版本。
Using username "sloba".
sloba@***.***.*.*'s password:
Welcome to Linux Mint 17.2 Rafaela (GNU/Linux 3.16.0-38-generic x86_64)
Welcome to Linux Mint
* Documentation: http://www.linuxmint.com
Last login: Sun Oct 11 18:25:32 2015 from ***.***.*.*
sloba@sloba-VirtualBox ~ $
loba@sloba-VirtualBox ~ $ python2.7
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
sloba@sloba-VirtualBox ~ $ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a =2
>>> b =5
>>>
sloba@sloba-VirtualBox ~/Desktop/myscripts $ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a =2
>>> b =5
>>>
>>> a,b = 2,5
>>>
>>> print a
2
>>&g