Python
vincentgoodturtle
这个作者很懒,什么都没留下…
展开
-
Python 字典
dict={‘a’:1,‘b’:2,‘b’:3}print (dict)只會output {‘b’ : 3} 因為key value中的key不可以duplicate, 而value可以 duplicate原创 2019-05-30 22:13:12 · 77 阅读 · 0 评论 -
Pandas package
example code:planets = {‘planet’: [‘earth’, ‘mars’, ‘jupiter’], ‘length_of_day’: [‘1’, ‘1.03’, ‘0.414’]}index = [0, 1, 2]planets_df = pd.DataFrame(planets, index=index)print(planets_df)...原创 2019-06-04 22:16:42 · 215 阅读 · 0 评论 -
Regular Expression
import rem=re.search(’(.?)\s(.)’,‘RegExr was created by gskinner.com, and is proudly hosted by Media Temple.’)print(m.group())print(m.group(1))print(m.group(2))原创 2019-06-04 13:35:13 · 331 阅读 · 0 评论 -
調用API
import requests#执行API调用并存储响应url='https://api.github.com/search/repositories?q=language:python&sort=stars'# 调用url,将响应对象存储在变量r中r=requests.get(url)print(r.text)# 查看请求返回的http 状态码,200表示请求成功pri...原创 2019-06-18 21:27:06 · 91 阅读 · 0 评论 -
re.search & re.match
用法一樣先import rem=re.search(reg pattern, strings)m.group(0) 是search到的所有stringsm.group(1)是第一組search到的stringsm.group(2)是第二組search到的strings#!/usr/bin/env python# -*- coding:utf-8 -*-import retext...原创 2019-06-07 11:36:19 · 355 阅读 · 0 评论 -
Python腳本開頭兩行
#!/usr/bin/python# -*- coding: utf-8 -*-第一行代表用urs/bin/下的python編輯代碼第二行代表腳本的代碼以utf-8編輯原创 2019-06-06 22:32:16 · 66 阅读 · 0 评论 -
abs() 返回絕對值,將負數變正數
abs(-10)–>output 10原创 2019-06-01 15:23:24 · 254 阅读 · 0 评论 -
Class Inheritance
class test(): def __init__(self,length1,width1): #創建對像的def self.length1=length1 #創建對像所需的methods self.width1=width1 def volume(self): #給予i...原创 2019-06-01 14:58:00 · 101 阅读 · 0 评论 -
圳
x = 9def t(): global x #put global x means you are using x in the global area x += 1 print (x)t()output: 10原创 2019-06-12 22:42:15 · 1748 阅读 · 0 评论 -
Markdown/ Generator 生成器
Markdown是一個輕量化的代碼編輯器, 用於更漂亮的展示代碼, 例子如github項目中的Readme#generator例子def fun(): for i in range(3): yield i #yield當作return使用,f=fun()print(f.__next__())print(f.__next__())print(f...原创 2019-06-12 20:13:40 · 514 阅读 · 0 评论 -
functon return value
如果一個function沒有return value, 預設return值為nonea=["Peter is a boy", "Mary is a girl"]def get_first_name(input_list): list=[] for i in range(len(input_list)): m=input_list[i].split() ...原创 2019-06-05 20:40:26 · 191 阅读 · 0 评论 -
while True
使用while True建立infinite loop, 使用break 中止infinite loop原创 2019-05-31 11:38:54 · 1285 阅读 · 0 评论 -
JSON.dumps/ JSON.loads
josn.dumps 將python dict type 轉換成 str type --> 用以寫入json文件json.loads則相反原创 2019-05-31 11:31:30 · 101 阅读 · 0 评论 -
什么时候会用到python装饰器?
https://wiki.python.org/moin/PythonDecoratorLibrary原创 2019-06-25 12:14:48 · 568 阅读 · 0 评论