pip upgrade python -m pip install --upgrade pip -ihttp://pypi.douban.com/simple --trusted-host pypi.douban.com
Depend on downloading pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn module name
Since the default mirror download is particularly slow and download timeouts often occur, you can directly specify the mirror download here
http://pypi.douban.com/simple/
Douban http://mirrors.aliyun.com/pypi/simple/
Ali http://pypi.hustunique.com/simple/
Huazhong University of Science and Technology http://pypi.sdutlinux.org/simple/
Shandong University of Technology http://pypi.mirrors.ustc.edu.cn/simple/
University of Science and Technology of China https://pypi.tuna.tsinghua.edu.cn/simple
Tsinghuapip
folder in the specified location of your computer and create the pip.ini
file[ global]
# Configure the mirror source,Choose by yourself
index-url = http://pypi.douban.com/simple
# Add the source as a trusted host, otherwise an error may be reported 3
trusted-host = pypi.douban.com
# Cancel every version update check of pip
disable-pip-version-check =true
# Configure download link timeout
timeout =120
# -*- coding: cp-1252 -*-
\
character to escape specific characters. If you do not want to escape, add r
before the stringprint ('string','test'*3)
string testtesttest
There are two indexing methods, one is from left to right 0, the other is from right to left -1>>> test ='helloword'>>> test[1:5]
ello
>>> test[:]
hellowrd
>>> test[5:]
word
>>> test[-1:-6]
loword
The basic properties of list
are similar to those of java, which can be inserted, appended, modified, intercepted (the official term in python
is slice and index). Index and trimming are the same. Here is the record of the additional usage
>>> a =[1,2,3,4,5]>>> a +[6,7,8,9][1,2,3,4,5,6,7,8,9]
Tuple
TupleThe nature of the ancestor is roughly the same as that of list
. The difference is that the element attribute of the ancestor cannot be changed (not including the element in the ancestor as an object). The ancestor is enclosed by brackets and connected by commas.
>>> a =(1991,2014,'physics','math')>>> print(a, type(a), len(a))(1991,2014,'physics','math')<class'tuple'>4
sets
and dictionary Dictionaries
A set is unordered and non-repetitive data. The way to create a set is set
(), and ()
is to create an empty dictionary. Both the set and the dictionary are included by ()
set
>>> student ={'Tom','Jim','Mary','Tom','Jack','Rose'}>>> print(student) #Duplicate elements are automatically removed
{' Jim','Jack','Mary','Tom','Rose'}>>>'Rose'in student #membership testing
True
>>> # set can perform set operations
...>>> a =set('abracadabra')>>> b =set('alacazam')>>> a
{' a','b','c','d','r'}>>> a - b #difference of a and b
{' b','d','r'}>>> a | b #Union of a and b
{' l','m','a','b','c','d','z','r'}>>> a & b #the intersection of a and b
{' a','c'}>>> a ^ b #elements in a and b that do not exist at the same time
{' l','m','b','d','z','r'}
dictionary
>>> dic ={} #Create empty dictionary
>>> tel ={'Jack':1557,'Tom':1320,'Rose':1886}>>> tel
{' Tom':1320,'Jack':1557,'Rose':1886}>>> tel['Jack'] #Main operation: query by key
1557>>> del tel['Rose'] #Delete a key-value pair
>>> tel['Mary']=4127 #Add a key-value pair
>>> tel
{' Tom':1320,'Jack':1557,'Mary':4127}>>> list(tel.keys()) #Return a list of all keys
[' Tom','Jack','Mary']>>> sorted(tel.keys()) #Sort by key
[' Jack','Mary','Tom']>>>'Tom'in tel #Membership test
True
>>>' Mary' not in tel #Membership test
False
>>> dict([('sape',4139),('guido',4127),('jack',4098)]){'jack':4098,'sape':4139,'guido':4127}>>>{x: x**2for x in(2,4,6)}{2:4,4:16,6:36}>>> dict(sape=4139, guido=4127, jack=4098){'jack':4098,'sape':4139,'guido':4127}
Recommended Posts