||
Python Village - INI2: Variables and Some Arithmetic
变量Variables,是计算机语言中能储存计算结果或能表示值抽象概念。
在Python中,基础的数据类型分为strings和numbers。numbers有两类:integers(整数,包括正数与负数)和floats(浮点数,带有小数点)。可以通过下面的方法赋予变量以数值:
>>>
其中,a、b、c均是integers,而'a - b is’是一个string,Python返回的内容就是“a - b is 300”。
几种常用的计算符号:
(加法)
(减法)
(乘法)
(除法)
(余数)
(幂运算)
注意:当除法运算遇到余数时,python只返回正数:
>>>
如果想得到后面的剩余的值,就必须将18(默认为integers类型数据)改为floats数据类型:
>>>
或者
>>>
在Python中,单个“=”号代表给变量赋值,比如“a = 3”,就是把3赋给变量a;而两个“==”就是相等的意思,比如:
>>>
提示出现错误,a为变量,没有进行赋值,所以并不等于2
>>>
首先给变量a赋值为2,然后“a == 2”返回值为“True”,说明a与2相等。
在Python中,string类型数据就是字符、数字及其他符号的集合,可以用“=”给变量赋值string类型数据:
>>>
string类型数据必须加上"或者',内部可以随意加上引号:
>>>
string类型数据的运算与numbers的运算稍微有所差异:
>>>
Problem
Return: The integer corresponding to the square of the hypotenuse of the right triangle whose legs have lengths a and b.
3 5
34
这个就是给你两个数,然后计算两个数平方之和
>>>
Rosalind is a platform for learning bioinformatics and programming through problem solving. Take a tour to get the hang of how Rosalind works.
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-6-8 04:46
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社