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

Python crawler Lecture 1

編輯:Python

Python Environmental installation

  • Python Installation of interpreter
  • PyCharm Installation

Python Basics

1. I / O statement :

Output *print()* It's a python Built in functions , You can output the objects in brackets directly .
print('hello')
# result 
>>> hello
*print()* You can also print multiple strings
age = 1
name = " Li Bai "
school = " Shenyang Institute of technology "
print(name, age, school) # Separated by commas 
# result 
>>> Li Bai 1 Shenyang Institute of technology
Input *input()* also python Built in functions
name = input(" Please enter a name :") # The words in parentheses are reminders 
print(name)
# result 
>>> Please enter a name : Li Bai
>>> Li Bai

2. Common data types

Common data types are numbers 、 list 、 character string 、 Dictionaries 、 Tuples 、 aggregate .

list :

Create a list
heroList = [' Ruban 7 ', " Angela ", " Li Bai ", ' Hou Yi ', 100, 10.1]
print(heroList)
# result 
>>> [' Ruban 7 ', ' Angela ', ' Li Bai ', ' Hou Yi ', 100, 10.1]
Accessing elements in a list ---- List name [ Indexes ]
print(" Hero for :",heroList[1],heroList[0])
# result 
>>> Hero for : Angela Ruban 7
Additive elements ----append Is to add elements at the end of the list
heroList.append(' Ruban master ')
print(' List after adding ', heroList)
# result 
>>> List after adding [' Ruban 7 ', ' Angela ', ' Li Bai ', ' Hou Yi ', 100, 10.1, ' Ruban master ']
Modifying elements
heroList[4] = " The sable cicada "
print(" Modified list ", heroList)
# result 
>>> Modified list [' Ruban 7 ', ' Angela ', ' Li Bai ', ' Hou Yi ', ' The sable cicada ', 10.1, ' Ruban master ']
Remove elements
del heroList[5]
print(" Deleted list ", heroList)
# result 
>>> Deleted list [' Ruban 7 ', ' Angela ', ' Li Bai ', ' Hou Yi ', ' The sable cicada ', ' Ruban master ']

3. The branch of judgment

if-else sentence

age = input(' Please enter your age :') # Enter the age 
print(type(age)) # Determine the type of variable is type function 
age = int(age) # Convert to numeric type int
print(type(age))
if age >= 18: # Judge the condition 
print(" Congratulations on your adulthood , You can go to the Internet bar ")
else:
print('sorry, You're still a baby ')
# Older than or equal to 18, result 
Please enter your age :18
<class 'str'>
<class 'int'>
Congratulations on your adulthood , You can go to the Internet bar
# Older than 18, result 
Please enter your age :3
<class 'str'>
<class 'int'>
sorry, You're still a baby

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