程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Basic learning of Python crawler (I)

編輯:Python

Hello everyone , I'm cabbage . Because of the needs of the project , Studying recently Python The reptiles of . This one is about Python The basic knowledge of , It is also an introductory knowledge point for learning reptiles ! If you get something after reading the article , You can support bloggers three times in a row ~, Hee hee .


List of articles

  • One 、 Preface
  • Two 、 notes
  • 3、 ... and 、 Variable
  • Four 、 identifier
  • 5、 ... and 、 keyword
  • 6、 ... and 、 Basic data type
    • 1、Number Numerical type
    • 2、 Boolean type
    • 3、 String type
  • 7、 ... and 、 Advanced data types
    • 1、 list
    • 2、 Tuples
    • 3、 Dictionaries
  • 8、 ... and 、 View data type

One 、 Preface

  • I will finish my study during the summer vacation Python Crawler video , From entry to project practice , One step at a time , And will continue to update Python Crawler column . Welcome interested partners to discuss relevant knowledge with you , For the mistakes in the article , Welcome to correct !

Two 、 notes

  • In our coding process , Because it takes a long time 、 Forget quickly 、 Complex code logic and other reasons , We can add comments as appropriate , To help yourself and other coders understand . therefore , Study Python It is very necessary to comment on , We should get into the habit of writing annotated code !

  • Like most programming languages ,Python There are two notes : Single-line comments and Multiline comment .

  • Single-line comments : With # start ,# Everything on the right is for illustration , It's not really a program to execute , To assist in explaining .

  • Multiline comment : With ‘’‘ Start , And ‘’’ end , Call it a multiline comment .

# Single-line comments , Explain the code 
print(' I want to pass subject one ')
''' Multiline comment Don't panic , Don't panic , There is moonlight under the sun . '''

3、 ... and 、 Variable

  • Basic grammar : Variable name = A variable's value
  • Variables are used to store data , You can change the value of a variable
question = " What songs do you like ?"
message = " a sunny day "
img = "https://item.jd.com/10046693874903.html"
print(question)
print(message)
print(img)

Running results :

Four 、 identifier

  • In computer programming languages , Identifier is the name used by the user when programming , Used to give variables 、 Constant 、 function 、 Statement block and so on
  • Identifiers are made up of letters 、 Underline and numbers make up , And the number can't start
  • Case sensitive
  • Cannot use keyword

Picture in the following figure X Is an example of nonstandard identifiers :

5、 ... and 、 keyword

  • When talking about symbols , We talked about not using keywords , that Python What are the keywords in ? Let's have a look :
FalseNonefromTrueandglobalasassertifbreakclassimportcontinuedefindelelifiselseexceptlambdafinallyfornonlocalnotorpassraisereturntrywhilewithyield

6、 ... and 、 Basic data type

  • Because it is a learning reptile , So learn the data types we need , Let's briefly introduce Python What are the data types , And simply understand their basic grammar .

1、Number Numerical type

# Number value type 
# int
money = 20
# float
value = 20.5

2、 Boolean type

# boolean Boolean type 
gender = True
sex = False

3、 String type

# string character string 
message = ' I'm a string '
information = ' strand '
# Nesting uses 
print("' I am a single quotation mark '")
print('" I am a double quotation mark "')

Running results :


It should be noted that , When there is a need , Single quotation marks and double quotation marks can be nested ~

7、 ... and 、 Advanced data types

  • Like I said before , This article begins with a brief introduction to the basic use of grammar , For in-depth learning , In the following article, we will introduce

1、 list

# Application scenarios : When crawling to multiple data , You can store this data in a list 
book_list = [' Education of love ', ' Journey to the west ', ' The romance of The Three Kingdoms ']
object_list = [' Break the vault of heaven ', 123, 3.5, True]
print(book_list)
print(object_list)

Running results :

2、 Tuples

age_tuple = (18, 19, 20, 21)
print(age_tuple)

Running results :

3、 Dictionaries

person = {

'name': ' I'm a cabbage ',
'age': 21,
'major': ' Computer science and technology '
}
print(person)

8、 ... and 、 View data type

  • stay Python in , Just define a variable , And it has data , Then its type has been determined , The system will automatically identify . That is to say, when using “ Variable has no type , Data has type ”
  • If you want to view the data type stored in a variable temporarily , have access to type( Variable name ), To see the data type stored in the variable
age = 21
print(type(age)) # int
name = ' I'm a cabbage '
print(type(name)) # string
score = 98.5
print(type(score)) # float
gender = True
print(type(gender)) # boolean
list_type = ['hello', 'world']
print(type(list_type)) # list list 
tuple_type = (12, 13, 14,)
print(type(tuple_type)) # tuple Tuples 
dict_type = {
'name': ' Cabbage ', 'age': 21}
print(type(dict_type)) # dict Dictionaries 

Thank you for reading , Progress together , Hee hee ~


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved