# -*- coding: UTF-8 -*-
import numpy as np
#变量
str_test="hell python"
int_test=123
float_test=123.5
print(str_test);print(type(str_test))
print(type(int_test))
print(type(float_test))
输出结果:
hell python
<type 'str'>
<type 'int'>
<type 'float'>
LIST
#List
months=[]
months.append("aaaa")
months.append(2)
months.append(2.5)
months.append("cccc")
print(type(months))
print(months)
print(months[0])
print(len(months))
print(months[1:3])#左包含,右不包含
print(months[1:])#左包含,右不包含
输出:
<class 'list'>
['aaaa', 2, 2.5, 'cccc']
aaaa
4
[2, 2.5]
[2, 2.5, 'cccc']
循环控制
#循环
months1=["aaa","bbb","cc","ddd",2]
for i in months1:
print(i)
n=0
while n< 3:
n+=1
print(n)
#多层循环
months2=[["aaa","bbb","cc","ddd"],[1,2,3,4]]
for month in months2:
print(month)
for month in months2:
for i in month:
print(i)
控制结构 字典
#控制结构 字典
if True:
print(True)
else:
print(False)
dic ={}
dic1 ={
"eee":555,
"fff":666
}
print(dic1)
print(type(dic))
dic["aaa"]="111";dic["bbb"]="222";dic["ccc"]="333";dic["bddd"]="444";
keys=dic.keys()
print(dic.keys())
for key in keys:
print(dic[key])
输出:
True
{'eee': 555, 'fff': 666}
<class 'dict'>
dict_keys(['aaa', 'bbb', 'ccc', 'bddd'])
111
222
333
444
WORDCOUNT
def wordConut():
list1=["aa","aa","xx","xx","xx","xx"]
dic2={}
for word in list1:
if(word in dic2):
dic2[word]=dic2[word]+1
else :
dic2[word]=1
print(dic2)
wordConut()
输出:
{'aa': 2, 'xx': 4}