Learning python way of (a)

One,

corresponding to the string s%

d% corresponds to an integer

print("xxx is s% ,xxx is d%" %(a,b))

two,

For python in a corresponding string manipulation functions can be called directly, e.g.

1.

strip () Removes whitespace characters
Print (string.strip ()) # can be removed in the blank string, added in parentheses "*" sign and the like can remove all the string "*"

Use: you can remove the space by mistake entered in the accounts when the user enters the password

name=input('user: ').strip()

2.

split () slicing string
= MSG ' Hello World Egon hahah say ' 
Print (msg.split ()) # default a space as a delimiter

The output will be a list of [ "hello", "world", ....] (tips: tuple is defined by "()", the list is defined by "[]", the dictionary is defined by "{}")

cmd='download|xhp.mov|3000'
info='root:x:0:0::/root:/bin/bash'

For this type of strings, it may be

split () parentheses plus ':' or '|' string to be segmented

 three,

With the basic syntax of the statement:

expression with [AS target]: 

# expression: Expression is a need to be performed; 
# target: or variable is a tuple, stored in the execution result is returned expression expression, optional parameters.
>>> with open('d:\\xxx.txt') as fp:
...     print(fp.read())
...
内容1
内容2

 

It works with the statement:

Keeping up with the latter statement is evaluated, the returned object __enter __ () method is called, the return value of this method will be assigned to the latter as key variable, with code behind when all blocks are executed, the call returns the object in front of __exit __ () method.

 with the statement that the most critical areas are evaluated object must have __enter __ () and __exit __ () These two methods, then we can achieve through their own methods to customize with these two statements to handle exceptions.

 

Guess you like

Origin www.cnblogs.com/1120lwk/p/11164096.html