type()p判断字符类型
0b01
1
0b10十进制
2
0o11十六进制
9
0xAE
174
bin (10) 二进制转换为十进制
'0b1010'
int(0o11)
9
任意进制转化为十进制
oct(100)任意进制转化为十六进制
’0o144'
2/1>>2.0 2//1>>2
bool类型 真假
int(True)
1
int(False)
0
bool类型(非0为True)非空时为True
在字符串中为空""[]时为False
字符串成对出现‘’ ”“
\n 换行 \r回车
d:\norce\etc
print("$1")
d:
orce\etc
print("\\norce\etc")
\norce\etc
a=input()
555
a
'555'
驼峰命名法:userName getSystemAttribute(java)
下划线命名法: user_name get_system_attribute
"hello " + " word"
'hello word'
"hello,word"[0:4]
'hell'
"hello,word"[0:5]
'hello'
age=11
name="pp"
print("(0) is (1) years old" .format(age,name))
11 is pp years old
a=123.323
b=int(a)
b
123
a=1.33333
print('{0:.3f}'.format(a))
1.333
俩个print输出时是会换行的如果不换行ze
print("a",end="+");print("b",end="+”)
a+b+
列表:
len([2,3,4])
3 当前数组的个数
a=[2,3,4]
a.count()括号内容出现的次数
a.append(6)
a
[2,3,4,6]
a.index()获取下标
a.insert(1,5)插入
[2,5,3,4]
替换
a[1]=0
[2,0,4]
a.pop()
4
a.pop(1)下角标
0
a.pop(2)
4
tuple 元组 不可替换
type((1))
int型
type((1,))
为tuple型
a in b
a元素是否在b 里面
max()求其中元素的ASCII码值的最大
min()最小
ord(‘’)查询ASCII值
>>> {1,2,3,4} & {3,4} 共同的部分
{3, 4}
set={1,3,4,5,5,3}
set
{1,3,4,5}
删除字典
del dicts[""]删除其中字符
值引用和地址引用:
int,str,tuple不可改变类型
list,set,dicr可改变类型
具体表现为:
不可改变类型:当重新赋值变量内容后,变量内存地址变化
可改变类型:当重新赋值变量内容后,变量内存地址不变
运算符:
1、算术运算符:%取余,**(指数),+,-,*,/,//
2、赋值运算符:+=,-=,*=,/=,//=
3、比较运算符:
4、逻辑运算:(参与运算本身是布尔类型,返回的也是布尔类型)and or not
5、身份运算 = 比较数值是否相同 is比较的是内存的地址是否相同
6、类型判断:isinstance(可以判断子类与父类的关系)
mem,value,type
is == isinstance
7、位运算符 &按位与 |按位或 ^按位异或 ~按位取反 <<左移 >>右移
按照二进制的方式运算
排序算法:
1、冒泡 :
2、选择
3、插入
4、希尔
5、快排
6、堆排
7、归并
8、基数
9、捅排
10、意大利面排序
流程控制:
if condition:
//todo 语句
else:
//todo
if condition:
//todo
elif condition:
//todo
elif condition:
//todo
else:
//todo
元组() 列表[]字典{}
第一个
#kind = input("please input the Car kind:")
#if kind == "AUDI":
#print("Expensive!")
#elif kind == "VOLVO":
#print("Safe First")
#elif kind == "BMW":
# \\print("for Rich person")
#\else:
# \\print("Give you a free BYD car")
#第二个
#num = input("please input a number:\n")
#num = int(num)
#if num % 2 == 0:
# if num % 3 == 0:
# print("你所输入的数字可以被2 和3 整除")
# else:
# print("Your input can be divided by 2")
#elif num % 5 == 0:
# if num % 2 == 0:
# print("your input can be divided by 2 and 5 ")
#第三个
#for a in range(0,11,2):#10不会被循环到即到10退出
# print(a)
#list = ["hello","word","test","redhat"]
#for a in list:
# print(a)
#dicts = {"pason":"
[email protected]","mike":"
[email protected]"}
#for a in dicts:
# print(a)
# print(dicts[a])
#tuple_t = (1,True,"linux")
#for a in tuple_t:
# print(a)
#arr = [3,1,2,5,4]
#for a in range(5-1):
# for b in range(5-1-a):
# if (arr[b] >arr[b+1]):
# arr[b],arr[b+1]=arr[b+1],arr[b]
#print(arr)
#for a in range(2,99):
# if a % 2 != 0:
# pass
# if a % 3 != 0:
# pass
# if a % 5 != 0:
# pass
# if a%7 != 0:
# print(a)