Member-only story
13 Unused Python Features
Python is one of the top programming languages, and it has many hidden features that many programmers have never used. In this article, I will share 13 Python features that you may have never used.
1. List Stepping
This is a step parameter that can split your list by taking several steps. Additionally, you can use the step parameter to reverse integers. Take a look at the code example below.
# 列表Stepping
data = [10, 20, 30, 40, 50]
print(data[::2]) # [10, 30, 50]
print(data[::3]) # [10, 40]
# 使用 stepping 翻转列表
print(data[::-1]) # [50, 40, 30, 20, 10]
2. find () method
The find () method is a great feature that can search for any starting index number of any character in a string.
# 查找方法
x = "Python"
y = "Hello From Python"
print(x.find("Python")) # 0
print(y.find("From")) # 6
print(y.find("From Python")) #6
3. iter () function
The iter () method is useful for iterating lists without any loop help. This is a built-in method, so you don’t need any modules.
# Iter()
values = [1, 3, 4, 6]
values = iter(values)
print(next(values)) # 1
print(next(values)) # 3
print(next(values)) # 4
print(next(values)) # 6
4. Documentation testing in Python
The Doctest feature will allow you to test your functionality and display your test report. If you check the example below, you need to write a test parameter in three quotes…