day04 finishing

Recap

variable

What is variable

State of things in the world described in

Compositional variables

Variable name (a descriptive sense; to accept variable)

Assignment symbol (=)

Variable values ​​(specific values)

Naming the variable name

  1. It has some practical significance
  2. By the letter / number / underscore, can not start with a number
  3. Use keywords can not be named

Note

Single-line comments

  1. Subsequent characters fail
  2. Explain a line of code

pycharm in shortcuts: ctrl + /

Multi-line comments

'''多行注释'''

Use turtle library

pencolor 画笔颜色
pensize 画笔大小
penmode 画笔颜色控制

goto 到达某一点

seth 绝对方向
left 相对向左
right 相对向右

fd 前进
bk 后退
circle 画圆

pu 抬起画笔
pd 落下画笔

fillcolor 填充颜色
begin_fill 开始填充
end_结束填充

Not to skip playing 30-60 minutes (or Referring answer)

Afternoon time:

Up 14:20 -14: 30 to wash my face (regardless of the storm are not stuck doing, habit)

14: 30-16: 00 am reviewing the content, did not finish the review does not continue (), review finished - rest, too much time can be

Robot, the point on the dry matter --- a habit / teacher knock code way ideas / thoughts (knock on a line of code) - "Morning understand, write to job

Intact (for exactly the same) knock - "First of all is to have the basic skills (study hard) -" Innovation

A data type based

In order to describe the state of things in the world, and therefore have a data type (founder predetermined Python)

A digital type

(A) Plastic

  1. Role (ID / numbers)
  2. Defined way
  3. Instructions
#加+减-乘*除/取余%取整//幂**
cmath模块

(B) Float

  1. Action (height, salary, decimals)

  2. Defined way

    Cast (Dynamic Language) language is not static cast

  3. Instructions

    With plastic

Second, the string type

What is the string: character (all content null character, enter the call character), the string up

(A) action: Name / Sex

(B) defined manner

Single or double quotes string up

Three single / double quotes may wrap

(Iii) use of

startswith: begin with ~

endswith: to end ~

Only strings may be used, other data types can not be used

  • Index values

    Index - "describes the character position, starting from 0

    print(pome[0])
  • Index sliced

    print(pome[0:7])
    #顾头不顾尾
  • Steps

    print(pome[0:7:3])
    #间隔取值

Third, the type of list

What is the list: a plurality of stored values ​​for (a string can store a value)

(A) action: Hobbies

(B) defined manner

With [] storage, a plurality of spaced elements (of any data type) with a comma

hobby_list = ['a','b','c','d','e',['f','g']]

(Iii) use of

  1. Index values
print(hobby_list[4][0]) #['f','g']中取值f
  1. Index sliced
print(hobby_list[0:4])
print(hobby_list[:4])#如果没写,默认为0
print([0:])#如果没写,默认为最后一个
  1. Built-in method

    #append 加值
    hobby_list.append('read')
    print(hobby_list)
    
    #索引修改值
    hobby_list[0] = 'singing'
    print(hobby_list)
    hobby_list[:] = 1,1,1,1,1,1
    print(hobby_list)
    

Fourth, the dictionary type

What is the key-value pair (key: value)

Dictionary: a plurality of keys within the {} (typically a string, having a descriptive sense) values ​​(specific values, and may be any data type) of

yy_infO_dict = {'name' :'jinyuyang','height':180,'weight':150,'hobby_list':['jiao','jump','dancing']}

Instructions

print(yy_info_dict['name'])#按key取值

yy_info_dict['height'] = yy_info_dict['height'] + 1

#del删除值

del yy_info_dict['height']

#split切割
s = 'a+b+c+d'
print(s.split('+'))#按照+把字符串切开,然后把切开的元素放入列表内

#join
lis = ['a','b','c','d']
res = '+'.join(lis)#按照字符串把列表里的每一个元素取出来拼接

Two, jieba module

(A) jieba library

Generally used to separate words

import jieba
res = jieba.lcut('中国是一个伟大的国家')# 第一个就是尽量长
res = jieba.lcut_for_search('中国是一个伟大的国家')#把第一个的长的单词继续切割

res = jieba.lcut('中国是一个伟大的国家',cut_all = ture)# 把所有的可能切出来

(B) installation

pip equivalent Mall

Pip install jieba mounted input on the command line

Enter pip uninstall jieba uninstall

Mirror source

Three, wordcloud module

#pip install wordcloud
#pip install matplotlib
#pip install imageio

#ctrl + r 刷新

s = "香港激进示威者25日进一步将暴力升级,在荃湾街头向警务人员投掷砖头和汽油弹,聚众围攻并追打警员,打砸破坏沿途多间店铺,已有5名警员遇袭受伤送院,对这种严重损害香港社会和谐安定的暴力行为,必须予以最强烈的谴责!"
s_list = jieba.lcut(s)#把字符串切割成列表
s = ' '.join(s_list)#把列表拼接成字符串

w = wordcloud.wordcloud(width = 1000,height = 1000,font_path = r'C:/windows/Fonts/simsun.ttc')#生成一个词云对象
w.generate(s)
w.to_file('nick.png')

#mask标记:首先找到一个白色底的图片

import jieba
import wordcloud
import imageio
import imread

mk = imread('wujaioxing.png')#把图片读入内存

s = "香港激进示威者25日进一步将暴力升级,在荃湾街头向警务人员投掷砖头和汽油弹,聚众围攻并追打警员,打砸破坏沿途多间店铺,已有5名警员遇袭受伤送院,对这种严重损害香港社会和谐安定的暴力行为,必须予以最强烈的谴责!"

s_list = jieba.lcut(s)
s = ' '.join(s_list)

w = wordcloud.WordCloud(width = 1000,height = 1000,font_path = r'C:/windows/Fonts/simsun.ttc')
w.generate(s)
w.to_file('nick2.png')

Guess you like

Origin www.cnblogs.com/wick2019/p/11413429.html