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

Summary of key points to note in Python

高洛峰
Release: 2017-03-10 14:21:07
Original
1003 people have browsed it

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)
Copy after login

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
Copy after login

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
Copy after login

4. Classes and objects

【Python】str类方法说明
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template