Python_way, day2 string, list, dictionary, time module

Source: Internet
Author: User

Python_way, day2 string, list, dictionary, time module 1, Input:

2.0 3.0 Differences

2.0 in

If you want the user to interact with the input string:

Name=raw_input ()

If

Name=input () is to pass what is the corresponding what, want to enter the string need to add "" "quotation marks, if not added to think that the incoming is a variable.

A= "hahaha"
User=input ("Shuru:")
Print (user)

Shuru:a
hahaha

3.0 in

Only input ().

So it's sometimes necessary to use a method to determine whether the input is a character or a number.

List.isdigit () detects whether the input string content is a number

List.isalnum () detects whether the input string content is a character

2, Getpass

Getpass.getpass ("passwd")

3, Inverted storage: 1, there is no installation of the default library is the standard library 2, need to install to pour the library is a third-party library how to install the third library: As long as the Python environment is installed with pip command to install the PIP Pip install pip Uninstall watercress has China's own mirror source.

Import Os,sys,time .....

In Python, if you execute a command with the SYS module, you can only store the return value after assigning the result of the command, and if you want to get the contents of the execution command, you will need to use Popen res=os.popen ("Ipcinfog"). Read print (RES)

Self-written module has 2 places can be put 1, current directory 2,python\\lib\\sit-packages | Dist-packages: The system default priority is poured into the current directory and the system is placed in the Dist-packages

What the hell is 4,PYC? What is PYC? In a Python program, if you import a library, the. pyc file is generated, and Python2 is generated to the current directory of the program Python3 is moved to __pycache__

This is because the Python program is compiled first, after the interpretation, because the first compiled so that Mr. PYc is the compilation of the file, and then the Python interpreter program in the file is interpreted line-wise to the machine can read the language.

5. Data type

Type () view input type

List

Dict

Integral type, long integer, (long integer This does not have long in python3.0) Boolean value: TRUE or false name[0] to get the first position in the list of elements, and so name[-1] to get the last Name[0:2] value 0 12 2 elements, Gu tou Regardless of the tail Name[-4:] from 4 to the last Name[:5] take the first five

list[Opening number: End number: Step size]

Modified: name[1]= "Wangminglong", renamed Insert: Name.insert (2, "Minggou") is split into a third position, subscript is 2 append: Name.apend () Append Delete: Name.remove ("Minggou") Delete the specified element value specifies the drop subscript: Name.pop () default specifies to delete the last subscript example
a=[1,2,3,4,5]
A.pop (2)
Print (a,a[2])
Put together two lists: Cousin expands into a new list name.extend (name2) name.reverse () reverses Name.sort () sort python2 if characters and numbers are mixed together so      RT sort, but Python3 can not be mixed together in the sorting, but if the number is caused to become a string name.copy do not copy the deep structure import copy copy.copy and name.copy the same Copy.deepcopy will copy deep-seated data deepcopy a list with a new name, change all changed, if copy.copy to the new value to modify, the original does not change the job title:

a=[1,2,3,9,4,5,6,7,9,7,4,2,3]

Get rid of a number in there.

Ideas:

Loop the values you want to change in a.

And then every time the loop finds his place, he's going to get rid of that number.

For i in Len (A.count (9)): #多少个9就循环多少次

B=a.index (9) Find this 9 index position every time

a[b]=9999 to modify this position

String: Remove whitespace, name.strip () default before and after removingspace, newline character specifies to take off one of the preceding charactersName.sprit (",") splits the split into lists-------> list. Join together to put the list------"string Name.format

Mes= (Hello,{name},i am {my})

Mes2=mes.format (name= ' xiaoming ', (my) = ' daming ')

Mes= (Hello,{0},i am {1}). Format (' xiaoming ', ' daming ')

Name.find (' SDFs ') finds the SDFs in the string??? The experiment wasn't successful.

Age.endswith () with what ends Age.startswith () with what to start upper () uppercase lower () lowercase

Tuples: function can only be counted, find Name.format

Dictionary:

    

Dictionary: Key in dictionary auto-weight ·  Dict.get () Get to No value no error · dict[] No value error dict.update () Some updates, no replacement dict.items () convert the dictionary into a list, but it takes time.     Big data is not recommended. 2.0 Dict.has_key 3.0 without 3.0 is used same in dict:

Dict.setdefule (K,V) If key has, then remove, no then join Dict.fromkeys ([1,2,3,4], "ddd") Dict.phpitem () random Delete Dictionary An object, it is recommended not to use.

=======================

Self-learning Module

Time

Import time


Mister into a mark of time
Print (a)
1463628250.9810724

2,aa=time.localtime (a)
And then put a mark to record the cost of time

3, and finally use strftime to output the time () inside is the input format, this time variable
Bb=time.strftime ("%y-%m-%d%h:%m:%s", AA)
Print (BB)
2016-05-19 11:24:10

Python_way, day2 string, list, dictionary, time module

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.