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 .
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 . '''
Basic grammar :
Variable name = A variable's value 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 :
Picture in the following figure X Is an example of nonstandard identifiers :
# Number value type
# int
money = 20
# float
value = 20.5
# boolean Boolean type
gender = True
sex = False
# 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 ~
# 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 :
age_tuple = (18, 19, 20, 21)
print(age_tuple)
Running results :
person = {
'name': ' I'm a cabbage ',
'age': 21,
'major': ' Computer science and technology '
}
print(person)
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 ~