Create a list
Copy Code code as follows:
Sample_list = [' A ', 1, (' A ', ' B ')]
Python list Operations
Copy Code code as follows:
Sample_list = [' A ', ' B ', 0,1,3]
Get one of the values in the list
Copy Code code as follows:
Value_start = sample_list[0]
This article describes how to convert string and dictionary types in Python, for more information about how to convert string and dictionary types in Python, see the following example. The specific method is as follows:
1.
' Age=28Addr='Chengdu' Money='200w'Cars='1w Units'words='INSERT INTO user values ("%s", "%s", "%s", "%s", "%s", "%s");'% (User,sex,age,addr,money,cars)#order can not be chaotic, must be in order toPrint(words)The output is:Insert into user values ("Emily", "female", "28", "Chengdu", "200w", "1w Station")Mode 2user ='Emily'Sex='female' Age=28Addr='Chengdu' Money='200w'Cars='1w Units'SQL='INSERT into user values ({name},{sex},{age},{addr},{qian},{che})'New_sql=sql.format (age=age,che=cars,name=use
This article describes how to convert a python string to a Moles code. it involves Python string and encoding operations and is very simple and practical, for more information about how to convert a
1. Using the list method to convert a string to a character list, the list function converts the string to a separate letter650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/8F/62/wKiom1jcnIuAS2YyAAAIKyYOUwI949.png "titl
Convert a python datetime string to a Unix Timestamp
Today, I encountered a problem when I used python to write a small program for capturing web pages. The time string on the page, for example, '(17:38:49)', needs to be converted
UNIX timestamp. The strtotime function was
, along with the following newline character, is ignored:1>>>Print("""2 ... usage:thingy [OPTIONS]3 ...-h Display this usage message4 ...-h hostname hostname to connect to5 ... """)6 usage:thingy [OPTIONS]7-h Display This usage message8-H hostname hostname to connect to9 Ten>>>
2-5 rows of three points is a prompt
Line 1th has been used \ implements the continuation function, so u becomes the first character of the string
The last cha
Answer: (http://stackoverflow.com/) PS: This website solves my many questions ah, everybody more on>>>s= ' \u9648\u4f1f\u9706\u5176\u5b9e\u662f\u4e2a ' >>>print s.decode (' Unicode-escape ') >> > This is actually a First you have a string similar to this:\u9648\u4f1f\u9706\u5176\u5b9e\u662f\u4e2aSo you try to print directly, hoping to become Chinese>>>s = ' \u9648\u4f1f\u9706\u5176\u5b9e\u662f\u4e2a ' >>>print s>>>\u9648\u4f1f\u9706\ U5176\u5b9e\u662
This article mainly introduces the basic operations of Python list, dictionary, and string. This article summarizes the most basic and commonly used operations, for more information, see create a list.
The code is as follows:
Sample_list = ['A', 1, ('A', 'B')]
Python
}–dict.update (DICT2) adds A dictionary dict2 key-value pair to the dictionary Dict–dict.clear () Delete all the elements in the dictionaryCollection,There can be only one string or list in the collection, which is used to repeatA=set (' Novogene ')A=set ([1,2,3,4,5,1,1])? How to update a collectionA=set ([1,2,3,4,5])–a.add (6) Adding an object in collection a 6–t=[6,7,8]–a.update (t) adds an iterator to an
)False: Roman numerals, Chinese numeralsError:byte number (single byte)32, S.isnumeric (), BOOLWhether the string contains only numbersTrue:unicode numbers, full-width numerals (double-byte), Roman numerals, Chinese numeralsFalse: NoneError:byte number (single byte)33, S.isdigit (), BOOLWhether the string contains only numbersTrue:unicode number, byte digit (single byte), full-width digit (double byte), Rom
4
radiansdict . Get (Key, Default=none) Returns the value of the specified key if the value does not return the default value in the dictionary
5
radiansdict.has_key (key) if the key Returns true in Dictionary Dict otherwise returns false
6
radiansdict.items () Returns a traversed (key, value) tuple array in a list
7
radiansdict.keys () Returns a dicti
. 2. The index of the first element of a sequence is always 0. What if the index is negative? Python starts counting from the right, the last element, and the last element's index is always-13, the string literal (as well as the other sequence literals) can use the index directly, without needing a variable to refer to them 4, if a function returns a sequence, you can also index the result of the return 5,
Python sequence: string, list, tuple sequence: A structure built-in function that contains a sequence of objects: str () list () tuple () can use STR (obj) to convert object obj to String lis
[TOC]@ (B5 python) [Python]Python Flip string (reverse string) Simple step is-1, which is the flip of the string (common)def reverse1(): s=input("请输入需要反转的内容:") return s[::-1]reverse1()def reverse2(s): if s=="": ret
[k]) #打印key和value的值, recommended this way, faster4, tuple operationA python tuple is similar to a list, except that the elements of a tuple cannot be modified.Tuple= (' A ', ' B ', ' C ', ' d ', ' e ')tuple = (' a ',) #元组中只包含一个元素时, you need to add a comma after the elementaccessing tuplesTuple[key]modifying tupleselement values in tuples are not allowed to be modified, but they can be combined in groups of
In Python programming, the conversion between strings and lists is often involved, and the conversion between the two is done in a comb.1. List converted to stringCommand: List ()Example:2. Convert String to ListCommand: "". Join (list
python script#!/usr/bin/env python# -*- coding: utf-8 -*- import sys print sys.argv 5.2 Sys OS module small notePython's strength is that he has a very rich and powerful standard library and third-party library, almost any function you want to implement has the corresponding Python library support, later in the course will be in depth to explain the various li
the current cursor position in the file ##文件的光标的移动# obj.seek (0) #光标回到文件最开始处, the second argument can not be written, the default is the start of a file 0# Obj.seek (0,0) #光标回到文件最开始处Obj.seek (12,0) #光标回到以文件0开始, 12th characterPrint Obj.tell ()Obj.seek (6,1) #光标从当前位置1开始, 6th characterPrint Obj.tell ()Obj.seek (3,2) #光标从文件最后2开始, 3rd characterPrint Obj.tell () #0 displays the current position of the cursor, which is the No. 0 character# Seek Summary# second argument, 0 for file start, 1 for file cu
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.