Variables: describes the state of things in the world of things, variable name = variable value
In order to describe the state of things in the world, and therefore have a data type: for data classification (Python predetermined founder)
Digital Type: Integer int float float
Integer:
1. Role: ID / telephone number
2. Define the way (Python and reality)
nick_id=360281
nick_id1=int(360288) #未来讲强制数据转换会详细讲
print(nick_id)
print(nick_id1)
3. Usage:
x=1
y=2
print(x/y)
print(x+y)
print(x-y)
print(x*y)
print(x%y) #取余
print(x**y) #幂
print(x//y) #取整
import cmath #科学计算器
print(cmath.pi)
print(cmath.e) #自然底数
Float:
1. Role: Salary 43000
2. Define ways:
salary=4.3
print(salary)
height=int(180.6)
salary1=float(3) #强制类型转换(动态语言),静态语言不能改变
print(salary1)
print(height)
3. Usage: integer and exactly the same
String
What is the string: character (all content null character input) + string (string up, which is a string of characters) is an empty space character
1. Role: Description Name / Sex
2. Define ways:
name="nick" #单双引号内把字符串起来
name1='nick'
height='nick"s height' #读取第一个引号的时候,字符串开始,第二个引号结束。
height1="nick's height"
#三单双引号可分行
poem='''梅谷劳
美国人
每个人'''
print(poem) #字符串开始符是三引号''',结束符也必须是三引号'''
name2=str('nick')
height_str='180'
print(height_str,type(height_str))
height2=float('180') #字符串变成浮点型
print(height2,type(height2))
height_int=180
height2=str(height_int)
print(type(height2))
name no character called variable name string together quotes
3. Use string (built-in methods - strings can be used)
s='nick handsome'
print(s.startswith('nick')) #startswith 以。。。开始
print(s.endswith('handsome')) #endswith 以。。结束
print(s.endswith('a')) #false
Index values
poem2='''美国人老是教供应商老是教欣赏想女生都是,你先看下技能'''
#索引 描述了字符的位置,从0开始,
print(poem2[3]) #正序
print(poem2[-1]) #倒序
#索引切片
print(poem2[0:7:2])#0-7个,顾头不顾尾,第三个数字是跨度/步长
print(poem2[6:9])
List
List Type (container type) discharge a plurality of data types
hobby_list=['just','tiaowu','sing','dsb','hhk',['singsing','dance']]
nick_hobby_list=list(['dance','singing','music']) #是否加小括号输出一样
print(hobby_list)
print(nick_hobby_list)
Use the list: the index value, change the value of the index, the index sliced
hobby_list=['just','tiaowu','sing','dsb','hhk',['singsing','dance']]
#索引取值 0 1 2 3 4 5
print(hobby_list[0:5:2])
print(hobby_list[5][0])
#索引修改值
hobby_list[3]='ren'
print(hobby_list)
hobby_list=1,1,1,1,1,
print(hobby_list)
list=['a','b','c','d']
res=''.join(list)
print(res)
res='*'.join(list) #按照字符串把列表里的每一个元素取出来然后拼接
print(res)
res='+'.join(list)
print(res)
s1='a*b*c*d'
print(s1.split('*')) #按照*把字符串切开,然后把切开的元素放入列表内
dictionary
What is dictionary: a plurality of key-value pairs {}
Keys (typically a string, having a descriptive sense) values (specific values, the value of any data type) for -key: value (data type)
Dictionary use:
ldd_info_list={'name':'lidandan','height':160,'weight':99,'hobby_list':['dance','singing','trip']}
print(ldd_info_list)
print(ldd_info_list['name']) #按key取值print(ldd_info_list['weight'])
ldd_info_list['weight']=ldd_info_list['weight']-1 # 98 按key修改值print(ldd_info_list)
print(ldd_info_list)
#del删除值
del ldd_info_list['weight']
print(ldd_info_list)
Word cloud
import wordcloud
import jieba
from imageio import imread
#mask 标记
mk=imread('shandian.png') #把图片读书内存
s='lzl 是声音最好听的女明星,没有之一,所有女星比不了'
s_list=jieba.lcut(s) #把字符串切割成列表
s=' '.join(s_list) #把列表合成字符串w=wordcloud.WordCloud(font_path='C:\Windows\Fonts\msyh',mask=mk,background_color='white') #生成一个词云对象 词云外国人写的,默认支持英文
w.generate(s)
w.to_file('nick2.png')