have the ' K1 ' key, create the ' K1 ' key and its value (the value of the key is set to an empty list), and the index in the list Li is an odd-numbered element that is added to the empty list of the ' K1 ' key.If the dictionary has the ' K1 ' key and the K1 corresponding value is a list type, then the index in the
First, the string function1, Capitaliza first letter capital# name = ' Alex '# v = name.capitalize ()# Print (v)#2, all caps are lowercase, casefold can be transferred to many languages, lower can only be transferred to English.# name = ' AleX '# v = name.casefold ()# Print (v)# name = ' AleX '# v = name.lower ()# Print (v)#3, center string Center, Parameter 1 (required) is the total length, parameter 2 (op
(name.upper ()) print ("\nalex\n". Lstrip ()) #左边去空格或者回车print ("\nalex\n". Rstrip ()) # Go to the right side of the space or enter print (Name.strip ()) #两边都去空格print ("Funny keys\n") V=str.maketrans ("ABCdef", "123456") # number corresponding! Print ("Alex Li". Translate (v)) print ("Alex L". Replace (' l ', ' l ', 1)) print ("Alex Li". RFind ("L")) #找到最右边的的l and return to print ( Name.split ()) # The photo space is divided into the list print (Name.
One of the notes of software Web Architects _ complements the imperfect second of Linux commands with a Python script:Traverse (Linux) subdirectories (or folders) with a Python script and find the specified string, and display:1, directory location;2, (string) where the file name;3. The line number where the
instead of 0) plus 1. For ch in text:if (Ch.lower () No in alphabetlist): Continue else:ch = Ch.lower () Letterpos + = str (alphabetlist.index (CH) + 1) + ""Finally, return the string position, and don't forget to truncate the space at the end of the string. The complete code is as follows:Defalphabet_position (text): if (len (text) ==0): #ifthe textisblankthenreturnit Returntextalphabetlist=["A", ' B ',
= Set1.difference (Set2)#difference = minus public part-Set1-set2 Print(set3) Set3= Set1.symmetric_difference (Set2)#symmetry difference = set-intersection ^ Set1 ^ Set2 Print(SET3) forValinchSet2:Print(val)Print(Set2.pop ())#you can get one, there's no guarantee what you got. Print(Set2)if3inchSet2:set2.remove (3)#Judging, deleting elements Print(Set2) Set4= {1, 2} Print(Set4.issubset (Set1))#4 is a subset of 1, Set4 Print(Set1.issuperset (SET4))#1 contains 4. Set1 >= Set4if
one)%ra takes precedence over string conversions with the repr () function%s takes precedence over string conversion with the STR () function%d/%i turns into signed decimal number%ub converted to unsigned decimal number%ob turns into unsigned octal number%XB/%XB (Unsigned) turns to unsigned hexadecimal number (x/x represents the size of the converted hexadecimal characterlowercase%e/%e turns into scientifi
)#returns a copy of S, if shorter than W, from the beginning with 0 supplement, so that the length and W;S.center (Width,char)#returns a string with the width of the center length of s, or padding with an optional argument char or a space if one is available, such as WidthS.ljust (Width,char)#Ibid., left-aligned;S.rjust (Width,char)#Ibid., right alignment;S.encode (Endoding,err)#returns a Bytes object that represents the
#-*-Coding:utf-8-*-#author: RXS002#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. Yuan zuTup = (1,2,3,4,5)#元祖转为字符串, return: (1,2,3,4,5)Pri
Because the operands of the read and write methods of Python are all string. When the binary is manipulated, the string is converted to a list for parsing, and when the file is re-written, it is converted to string.>>> Import String
store more data than strings and find more convenientnames = ['Alex','Jack','Rain','Mack','Rain','Bob']#slicesPrint(Names[1:4:2])Print(names[-2:])Print(Names[:2])#Find IndexFirst_index = Names.index ("Rain")#to find the index of a second repeating value rainSecond_index = Names[first_index+1:].index ("Rain")Print(First_index, Second_index)#To delete a list elementdelNames[first_index+second_index+1]Print(names)#DeleteNames.pop (4)Print(names)#modifyi
When you learn that Python reads a file from a file and converts a string from a file into a list, you find that the file header has a \ufeff character.This problem was encountered before, the same is the Internet search for a half-day to solve, at that time just to solve the problem is over, but today encountered the same problem, know there is such a solution
types.(2) Sequence type operatorThe following are presented separately:
Member relationship operator: In,not in
for a string, it is to determine whether the character is in the string (in fact, this character is also a string object), for lists and tuples, is to determine whether the object belongs to the sequence of objects, for example, as follow
#-*-coding:utf-8-*-#List" "Learning Objectives: Additions and deletions can be found through the index, or through the slice lookup, the principle of the slice is left including right does not include" "L= ['Hadoop','Hive','R','ETL','python','R']#take the lastPrintL[1:]#take the second to the bottom .PrintL[1:-1]#step is 1, take onePrintL[0:-1:2]#Step 2, right to leftPrintL[3::-2]" "Count: Count the number
python-the contents of the HTML file to retrieve a specific URL address string, save it as a list, and use each URL to download the picture and save it to the hard drive, the regular re
Reference: http://blog.csdn.net/xwbk12/article/details/72734930
1, the target address: https://xianzhi.aliyun.com/forum/topic/1805/The contents of the following figure
Remove the
defIndex (self, value, Start=none, Stop=none):#real signature unknown; restored from __doc__ """L.index (value, [Start, [stop]]), integer-return first index of value. Raises valueerror if the value is not present. """ return0defInsert (self, Index, p_object):#real signature unknown; restored from __doc__ """L.insert (Index, object)--Insert object before index""" Pass defPop (self, index=none):#real signature unknown; restored from __doc__ """l.pop
One: string deletion1, the string itself is immutable, a string definition, after he is not able to do anything, so the addition and deletion is the copy of the original string copy of the operation, the original string is the original s
Python string/tuple/list/dictionary cross-transfer--coding:utf-8--1, Dictionary dict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '} dictionary converted to string, return: Python string/tuple/
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.