目录

派松笔记

Notes

1 Hello World!

Course link Girraffe Academy

  • install python 3 and pycharm
  • choose interpreter python 3
  • create a python file
  • print{“Hello, World!"}
  • Set variables (easy and any where, could be rewrite) (xx = xx)
  • is_Male = Ture / False (careful with the capital letter)

2 string

  • string variables "”
  • ex. abc = “string test”
  • any marks in "" can be achieved by \
  • string fuctions: abc.lower(), abc.upper(), abc.isupper(), combination is also ok
  • lens(abc), abc[0], strat with 0, check the text, vs. abc. index(“t”), the first t position will be found. abc.replcace(“test”, “variable”)

3 number

  • numbers
  • basic calculation works, print(3 * (4 + 5))
  • remainder, print(10 % 3)
  • define number variable, my_num = 28
  • convert number to string, str(my_num)
  • print out only can excute for same variables
  • ex, print(abc + my_num) will not work
  • absolute value, abs(my_num)
  • pow(3, 2), 3 *3
  • max(2, 3), find the max one, vs. min(2, 3)
  • round(3.2), get 3, round number
  • import (external) python math (module): from math import *
  • floor(3.8), ceil(3.8), sqrt(36)

4 input

  • name = input(“Enter your name: “)
  • age = input(“Enter your age: “)
  • print (“Hello " + name + “! You are " + age + “.")
  • multiple input available

5 calculator

  • default input is considered as string, so by calcu, convert number.
  • int(), float()
  • num1 = input(“Enter a number: “)
  • num1 = input(“Enter a number: “)
  • result = float(num1) + float(num2)
  • print(result)

6 mad libs game

  • color = input(“Enter a color: “)
  • plural_noun = input(“Enter a plural noun: “)
  • celebrity = input(“Enter a celebrity: “)
  • print(“Rose are " + color)
  • print(plural_noun + " are blue”)
  • print(“I love " + celebrity)

7 list

  • friends = [“Kevin”, “Karen”, “Jim”, “Oscar”]

  • print(friends[2])

  • negative number also works [-1] is last one, [0] is the first one

  • [1:3], only grab 1, and 2, not 3!

  • list fuctions

  • lucky_numbers = “[4, 8, 15, 16, 23, 42]”

  • friends = [“Kevin”, “Karen”, “Jim”, “Oscar”]

  • friends.extend(lucky_numbers) merge two list

  • friends.append(“Creed”) add in the end

  • friends.insert(1, “Kelly”) insert with position

  • friends.remove(“Jim”)

  • friends.clear()

  • friends.pop() remove the last element

  • friends.index(“Kevin”)

  • friends.count(“Jim”)

  • friends.sort() Alfabet and number order

  • friends.reverse() reverse the order

  • friends2 = friends.copy()

  • print(friends[2])

8 tuples

  • coordinates = (4, 5)

  • tuple object does not support item assignment

  • print(coordinate[1])

  • list vs. tuple, [] vs. ()

  • tuple is not mutable

9 functions

  • c

MOOC Python网络爬虫与信息提取

  1. requests
  2. robots.txt
  3. Beautiful Soup
  4. Projects
  5. Re
  6. Scrapy

- 完 -
「 加个鸡腿! 」
WeChat Pay
微信赞赏
Alipay
Paypal赞赏