python函数注释,参数后面加冒号:,函数后面的箭头→是什么?
函数注释示例:
def f(ham: 42, eggs: int = 'spam') -> "Nothing to see here":
print("函数注释", f.__annotations__)
print("参数值打印", ham, eggs)
print(type(ham),type(eggs))
f("www")
返回信息:
函数注释 {'ham':...
python标准库OS和SYS
sys
sys.path 列表 导入搜索的路径
import pprint
pprint.pprint(sys.path)
sys.path.append("F:\LXZ")
sys.argv 是个参数列表
sys.exit([arg]) 参数整数或者字符串 0成功 字符串一般是错误信息的
sys.modules 字典 载入的模块
sys.platform 字符串...
python测试和两个小工具
测试
先测试后编码 ---->测试驱动
对程序的各部分 建立测试----> 单元测试
1.支出需要的新特性,编写一个测试程序
2.编写特性概要代码
3.为特性的概要编写虚设代码
4.重写代码
#Test_area.py
from area import rect_area
height = 3
width = 4
correct_answer = 12
answer = rect_a...
python pillow 基础
pillow
python imaging library 是python生态中最有名的图片处理相关库
pip install pillow
一些基础操作
In [6]: os.listdir()
Out[6]: ['book.jpg', 'hy.gif']
In [7]: from PIL import Image
In [8]: im = Image.open('book.jpg')
...
itsdangerous token生成
发送激活邮件、链接
激活连接中,需要包含用户的身份信息
http://127.0.0.1/user/activate/3
id为3的用户激活
但这样发,很不安全 ,需要把用户的身份信息进行加密
pip install itsdangerous
from itsdangerous import TimedJSONWebSignatureSerializer as Seria
import t...
[LeetCode] 300. Longest Increasing Subsequence
题:https://leetcode.com/problems/longest-increasing-subsequence/description/
题目
Given an unsorted array of integers, find the length of longest increasing subsequence.
Example:
Input: [10,9,2,5,3,7,101...
[LeetCode] 583. Delete Operation for Two Strings
题:https://leetcode.com/problems/delete-operation-for-two-strings/description/
题目
Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in e...
[编程之美] 3.1 字符串循环移位包含
题目
s1 = AABCD, s2 = CDAA
Return : true
给定两个字符串 s1 和 s2,要求判定 s2 是否能够被 s1 做循环移位得到的字符串包含。
思路
以S1 = ABCD 为例,对其循环移位的后果为:
ABCD -> BCDA -> CDAB -> DABC -> ABCD
S1S1 = ABCDABCD
看出对S1做循环移位所得到的字符串都将...
[编程之美] 2.17 字符串循环移位
题目
将字符串向右循环移动 k 位
s = "abcd123" k = 3
Return "123abcd"
思路
方法一 翻转法
将子串 s[0:str.length() - k)] 翻转,子串s[str.length() - k,str.length()] 翻转。然后将整个字符翻转可以到最终结果。
eg:
将 abcd123 中的 abcd 和 123 单独翻转,得到 dcba321,然后对...
[LeetCode] 785. Is Graph Bipartite?
题:https://leetcode.com/problems/is-graph-bipartite/description/
题目
Given an undirected graph, return true if and only if it is bipartite.
Recall that a graph is bipartite if we can split it’s set of n...
[LeetCode] 207. Course Schedule
题:https://leetcode.com/problems/course-schedule/description/
题目
There are a total of n courses you have to take, labeled from 0 to n-1.
Some courses may have prerequisites, for example to take course ...
[LeetCode] 684. Redundant Connection
题:https://leetcode.com/problems/redundant-connection/description/
题目
In this problem, a tree is an undirected graph that is connected and has no cycles.
The given input is a graph that started as a tr...
[LeetCode] 345. Reverse Vowels of a String
题:https://leetcode.com/problems/reverse-vowels-of-a-string/description/
题目
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Input: "hello"
Output: "hol...
[LeetCode] 680. Valid Palindrome II
题:https://leetcode.com/problems/valid-palindrome-ii/description/
题目
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.
Example 1:
Input: "aba...
[LeetCode] 451. Sort Characters By Frequency
题:https://leetcode.com/problems/sort-characters-by-frequency/description/
题目
Given a string, sort it in decreasing order based on the frequency of characters.
Example 1:
Input:
"tree"
Output:
"eert"
...
JavaScript-截取字符串
引言在js中字符串截取函数有常用的三个slice()、substring()、substr()函数,同时还有一些方法如split() 、Join() 、indexOf()可以对字符串进行操作,来获得截取我们想要的字符串
周排行