python第三天
python开发ide:pycharm,eclipse
一、运算符
1、算数运算符
+ - * /
幂**
余%
求整数9//2=4
判断字符是否在字符串里面
in not in
name = "阿拉斯加" if "文件" in name: print("ok") else: print("not ok")
2、比较运算符
==
<
>
<=
>=
!=不等于
<>不等于
3、赋值运算
=、+=(c+=a等效于c=c+a)、-=、*=、/=、%=、**=、//=
4、逻辑运算
and、or、not
注:逻辑运算推荐使用括号,以明细逻辑关系
5、成员运算
布尔值
true
false
while true
二、基本数据类型
数字(int类型),所有的功能都放在int里
python3:无限制
python2:数字有长度
叫整形int,数字长度超限叫长整形long
常用功能
1、int(将字符串转换为数字)
例:a = int("123")
a=123
2、bit_length(将数字转换为二进制)
例:age = 5
r =age.bit_length()
print(r)
字符串(str)
常用功能:join、split、find、strip、upper、lower、replace
len、for循环、索引、切片
列表(list)
元组(tuple)
字典(dict)
布尔值(bool)