一、基础语法
1)#号注释
#python3
print("welcome to python3")
#输出print自带换行效果
welcome to python3
2)定义变量
Sarr = 66
Sstr = 'hi~,how are you doing?'
print(Sarr)
print(Sstr)
#输出
66
hi~,how are you doing?
3)print函数
#输出两位小数
ss = 3.1415926
print('%.2f'%ss)
#输出
3.14
#输出不自动换行并自带空格
sstr = "hi,how are you doing?"
print(sstr,end=" ")
print("this is the end")
#输出
hi,how are you doing? this is the end
5)字符相减
#字符相减
#函数ord将字符转为ASCII码
print(ord('c')-ord('a'))
#输出
2
6)python 中and 和 or
A and B or C 等同于 (A and B)or C
7)函数内修改全局变量
win = 0
equ = 0
#声明global之后即可修改
def judgement(tempStr):
global win
global equ
8)int强转 ‘1.1’类型的字符串会出错,用float强转不错
典型的数据结构有线性结构,非线性结构。
线性结构有 顺序表,链表,栈,队列。
非线性结构有 树,图。
1.python中的数组声明
#C++ arr[10] = {0}
pyArr = [0 for i in range(10)]
pyArr = [2,3,4,5,6]
2.python中Map的使用