1. String conversion to List' Hello world! '[' H ', ' e ', ' l ', ' l ', ' o ', ' ', ' W ', ' o ', ' r ', ' L ', ' d ', '! ']Where A is a string and a_list is a list2.List Convert to StringA_list = ['H','e','L','L','o',' ','W','o','R','L','D' , '! ']a="'. Join (A_list)//' He
Lists and groupingsSequence Overview:A data structure is a collection of elements that are organized in some way together . The elements can be numbers, characters, or even other data structures.In Python, the most basic data structure is the sequence (sequence).Each element in the sequence is assigned an ordinal----the position of the element, also known as Index, subscript. The first index is 0, the second index is 1, and so on.Python contains 6 bui
number of digits of integers and decimals:>>> '%2d-%02d '% (3, 1)' 3-01 '>>> '%.2f '% 3.1415926' 3.14 '%s always works, it converts any data type to a string:>>> ' Age:%s. Gender:%s '% (True)' Age:25. Gender:true 'For Unicode strings, the usage is exactly the same, but it is best to ensure that the substituted string is also a Unicode string:>>> u ' Hi,%s '% u '
字符串右对齐 and fills a new string with a space to a specified lengthA.rsplit () #去掉右边空格或换行符A.rstrip () #去掉字符串右边的空格A.strip () #去掉字符串中的空格A.split () #字符串切片The A.splitlines () #按行分隔 Returns a list that contains rows as elements, and if NUM specifies that only num rows are sliced.A.startswith () #判断是不是以参数中内容开头A.swapcase () #对字符串的大小写字母进行转换A.title () #把字符串转成标题格式A.capitalize () #把字符串首字母变为大写A.endswith () #判断字符串是否以指定字符或子
Python's common operations on redis (list, string, and hash structure operations) and pythonredis
All the discussions here are based on the python redis-py library.
Installation and use:
pip install redis
Then obtain a redis client:
redis_conn = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB)
There are five basic types of redis. Including
#-*-coding:utf-8-*-Http://www.cnblogs.com/linjiqin/p/3674356.html#1, DictionariesDict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '}#字典转为字符串, return: Print type (str (dict)), str (DICT)#字典可以转为元组, return: (' age ', ' name ', ' class ')Print tuple (dict)#字典可以转为元组, return: (7, ' Zara ', ' first ')Print tuple (dict.values ())#字典转为列表, return: [' age ', ' name ', ' class ']Print List (dict)#字典转为列表Print Dict.values#2, tuplestup= (1, 2, 3, 4, 5)#元组转
The example in this article describes how the list elements in Python are converted to numbers. Share to everyone for your reference, as follows:There is a list of numeric characters:numbers = [' 1 ', ' 5 ', ' 10 ', ' 8 ']You want to convert each element to a number:numbers = [1, 5, 10, 8]Use a loop to solve:New_number
The example in this article is a useful technique for Python implementations that ignore case-by-column ordering of strings. Share to everyone for your reference. The specific analysis is as follows:
Let's take a look at the following code:
string = ' ' The
stirng has many line in the
fIle
jb51 net
'
list_of_string = String.Split ()
print list_of_string #将字符串分离开, put in the
Description of the Python string, list, and dictionaryString, list, dictionaryThe function of a string stores a piece of data information. For example, info = ' I love Beijing tian An door ', can be directly adjusted when the adjustment, flexible and convenient, print (info)
1 #-*-coding:utf-8-*-2 3 #1. Dictionaries4Dict = {'name':'Zara',' Age': 7,'class':' First'}5 6 #dictionary converted to string, return: : ' First '}7 Printtype (str (dict)), str (dict)8 9 #dictionaries can be converted to tuples, returning: (' age ', ' name ', ' class ')Ten Printtuple (dict) One #dictionaries can be converted to tuples, returning: (7, ' Zara ', ' first ') A Printtuple (Dict.values ()) - - #dictionary to
1 #-*-coding:utf-8-*-2 3 #1. Dictionaries4Dict = {'name':'Zara',' Age': 7,'class':' First'}5 6 #dictionary converted to string, return: : ' First '}7 Printtype (str (dict)), str (dict)8 9 #dictionaries can be converted to tuples, returning: (' age ', ' name ', ' class ')Ten Printtuple (dict) One #dictionaries can be converted to tuples, returning: (7, ' Zara ', ' first ') A Printtuple (Dict.values ()) - - #dictionary to
1.stringThere are four ways to define a string:' ' " " ''' ''' """ """Subscript and slice of a string :as : name = abcdeffrom the leftmost number is from 0 The subscript starts from the rightmost number from the -1 StartSlice Syntax: [ start : end : step ]Note: The selected interval is left closed right open type, that is, from the "start" bit, to the end of the first bit end of the bit ( does not include t
(dict2,10) print (DICT4) #字典 (Dictionary) get () function returns the value of the specified key if the value does not return a default value in the dictionary. dict5={' name ': ' Gyh ', ' Age ':25}print (dict5.get (' name ', ' haha ')) print (Dict5.get (' name ', ' haha ')) #字典 ( Dictionary) update () function updates the dictionary dict2 key/value pairs to dict dict={' Name ': ' Zara ', ' age ': 7}dict02= {' Sex ': ' Female '}dict.update (dict02) print ("value:%s" %dict) #以上实例输出结果为: #Value:
A solution to empty rows during conversion from a python file string to a list !,
The file content is as follows:
Alex 100000 Rain 80000 Egon 50000 Yuan 30000 # There is a blank line here!
Now let's see how to handle it and convert it to a list!
Salary_info = open ("sala
times-fold difference in performance. Remember that the string is very large, do not use s=s+a[i] this way, because the constant creation of memory space to add, not only the program is very card, greatly consumes the resources, but also very slow.
____________________________________________________________
In Python:
Import time# First Way, appenda=[]t=time.time () for I in Range (1000000): a.a
python Converts the list continuous and non-contiguous elements to the specified stringBar User Questionshttp://tieba.baidu.com/p/3730249293a list of elements that are known to consist of a pure number (ordered by a small size), such asli=[1,2,3,4,5,7,8,15,20,21,22,23,24,28]write a function so that it returns the following stringstr= ' 1~5,7~8,15,20~24,28 'If the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.