Home  >  Article  >  Backend Development  >  Summary of key points to note in Python

Summary of key points to note in Python

高洛峰
高洛峰Original
2017-03-10 14:21:07962browse

This article introduces a summary of key points to note in python

1. Arithmetic operations are performed in python2.7 / The operation is not precise enough and you need to reference the _future_ class library

#!/usr/bin/env python
# -*- coding:utf-8 -*-
from _future_ import division
 val = 9/2
  
 print(val)

2. Range and xrange

【python2.7】 The performance of xrange looping is better than range, especially when the return is very large. Try to use xrange, unless you want to return a list.

In python3.5, only range has the same function as xrange!

#!/usr/bin/env python
# -*- conding:utf-8 -*-
s1 = range(1,10)
s2 = xrange(1,5)
print(s1)
print(s2)
for s in s2:
    print s

3. The use of judging in or not in

#!/usr/bin/env python
# -*- conding:utf-8 -*-
li = "Alex SB"
ret = "Al" in li
print(ret) # => True
li = ["alex","eric","rain"] 
ret = "al" in li
print(ret) # => False

4. Classes and objects

【Python】str类方法说明


The above is the detailed content of Summary of key points to note in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn