1.在python中有3种基本数据类型interage,floats,booleans;
2.声明变量为 varible =1
3.python是一种区分大小写的语言
4.基本运算符
+ ,-,*,**(幂运算),/ (除),%(取模)
5.函数实现
def Function():
....
return ...
函数以缩进分段。
6.python 行注释为 #this is comment
7.Python 多行注释为
“”
This is a comment for python
“”
8.type()函数返回变量类型
9.python 中的string
用’’或者” “包成
如 var_str=”Sherlock”
取第一个字符可直接 var_firstletter= var_str[0]
或者 var_firstletter=”Sherlock”[1]
\来实现转义字符
字符串基本函数
lower() 转换为小写
upper()转换为大写
如:
print(len(var_str),var_str.lower(),var_str.upper())
len(object) 求string长度
str() 将数字转换成字符串
str[0:n]方法得到自字符串
str[n:]得到n+1后的子字符串
.
print()打印函数
python六种比较方法==,!=,<,>,<=,>=
逻辑连接词 and ,or , not
if 语句格式
if condition:
Statement
if else 语句格式
if condition:
Statement
....
else :
Statement
....
Else if语句格式
if condition:
Statement
....
elif condition:
Statement
...
row_input实现输入
name=row_input(“attention statement”)
isalpha()判断是否为数字
import 导入模块和函数,类似c的include
from module import function
from module import *
list 普通链表的使用,可以动态增减
lst=[元素] 声明为list类型,内容为空
lst=[“name”,”year”] 则lst[0]的值为name
index(item)方法返回item在list中的下标
insert(index,item)方法在index插入item
sort()方法排序,默认从小到大
remove(item)
Tuple 固定数组,定义后元素个数不能改变
定义方式arr=(元素)
python 中的字典
dictionary={}空字典
在字典里添加或者更改一个key的value 格式为
dictionary[key]=value
删除del dictionary[key]
key 可对应一个列表
dictionary={key:[]}
用dictionary[key][index]进行调用