Python on 3² day trip (built-in functions, basic file opening and closing)

In fact, today met a number of not liking things, delay the learning process, but in the end, it is God you know, a bad mood today, not much content, but it is really his sister's difficulty, and test things out and look different, and units can be the same as yesterday, a nap woke up, the result of normal, ha ha ha.

On dry goods, built-in method:

abs absolute value
 # Print (abs (-1)) # ----> The results obtained:. 1 
#  
# All of iterables bool calculation for each element, all iterations True object is null or returns True 
# Test = [ 'Alex', '10'] 
# Print (All (Test)) # returns a value of True 
# test1 = [] 
# Print (All (test1)) # returns a value of True 
# test2 = [ '', 18 is ] 
# Print (All (test2)) # returns a value Flase 
#  
# the any of iterables in each of a bool operation, as long as one is true, true is returned 
# All the above opposite 
# Test = [ '' , 18 is] 
# Print (the any (Test)) # returns a value of True 
# test1 = [ '', {}, 0] 
# Print (the any (test1) returns a value of # Flase 
#  
# bin decimal binary Switch
# Hex decimal to hexadecimal 
# the OCT octal, decimal turn 
# the n-= 2020 
# # Print (bin (the n-)) # 0b11111100100 0B represents a binary number 
# # Print (hex (the n-)) # 0x7e4 0x hexadecimal representation number system 
# # Print (OCT (n-)) # 0o3744 0o octal number 
#  
# #Bytes in the form of a character string into bytes 
# name = 'Hello' 
# n-bytes = (name, encoding = 'UTF-. 8' ) 
# Print (n-) #encoding code table represents the corresponding form into bytes 
# # result B '\ XE4 \ XBD \ XA0 \ xe5 \ xa5 \ XBD' 
#  
# #decode bytes into the text, with the above bytes contrary, transcoding decoded reference must be the same Oh 
# test_name = n.decode (encoding = 'UTF-. 8') 
# Print (test_name) 
#  
#chr digital output corresponding to the ASCII code 
# Print (chr (98)) to output # B 
#  
# dict dictionary 
# the dir display method of an object following 
# Print (the dir (tuple)) # ----> Output tuple All methods in the objects 
#  
# divmod also calculated quotient and the remainder 
# Print (divmod (10,3)) # ------> the output is (. 3,. 1) 
#  
# the eval extracting data structure contained in a string 
# Test = "{ 'name': 'Alex', 'Age': '18 is'}" 
# Print (the eval (Test)) # -----> { 'Age': '18 is', 'name': 'alex'} 
# the n-dict = (eval (the Test)) #eval out is an iterator, turn a little to formally invoke a method 
# for k, v in n.items (): 
#      Print (k,V) where n # becomes an iterative dictionary 
# # acquires dictionary data types contained therein 
#= str_test '. 1 + 2 * (. 3 / 3-1) -2' 
# n-= the eval (str_test) 
# Print (n-) # ----> calculation result obtained -1.0 
#  
# a float return floating-point value 
#  
# the hash to be immutable hash hashed 
# hash value characteristics: a fixed invariable, without significantly increases with increasing length of the string, the hash value can not be thrust reverser according to the text content, the content hash constant does not change (that can be used file detection) 
#  
# Help detail a method of using an interpreter 
# Print (Help (map)) built-in function map output # explanation, all in English, I do not understand represents 
#  
# the isinstance corresponding data type determination data 
# print (isinstance ( 'hello, world ', str)) # returns a value of True 
#  
# about locals of all current local variable 
# Globals of all current global variables 
#  
# ZIP iterables correspondence of the two, two number of elements is not the same, subject to a small, over the corresponding ends of the 
#= A [ 'A', 'B', 'C', 'D'] 
# B = [l, 2,3] 
# Print (List (ZIP (A, B))) # output: [( 'a ',. 1), (' B ', 2), (' C ',. 3)] 
# may make the dictionary k, v values correspond 
# Test = {' Age ':' 18 is', 'name': 'Alex'} 
# Print (List (ZIP ((), test.values ())) test.keys) # output: [( 'age', ' 18'), ( 'name', 'alex')] 
#  
# max finding the maximum effect 
# two features: input iterables different types can not be compared, a default start value from the first comparison, the result does not continue to drop as par 
# equivalent of doing a for loop compares each 
#  
# primary stage using max 
# list_test = [1,24,56,3,100] 
# Print (max (list_test)) output # 100 
#  
# max using Intermediate 
#= list_test [( 'A',. 1), ( 'B', 2), ( 'C',. 1)] 
# Print (max (list_test)) # output is ( 'C',. 1) 
#  
# Next max is the high-order mode, the dictionary data comparison 
# pep_list = { 'Alex': 18 is, 'ZJL': 20 is, 'Axin': 40, 'zhaolei':} 18 is 
# Print (List (max ((ZIP (pep_list .values (), pep_list.keys ()))))) 
# output is [40, 'Axin'] 
#  
# max play the most advanced, a method can be entered after the 
# demand: obtaining the following dictionary oldest people 
# list_test = [ 
#      { 'name': 'Alex', 'Age': 18 is}, 
#      { 'name': 'ZJL', 'Age': 28}, 
#      { 'name': 'Zhao', ' age ': 33},
#     {'name':'kobe','age':40},
# ]
# 
#Print (max (list_test, Key = lambda dic: dic [ 'age'])) 
# output is { 'name': 'Kobe', 'Age': 40} 
#  
# where lambda dic: dic [ 'age' action] is to be taken out list_test each element (i.e., dictionary) corresponding to the value in the age 
# and the cycle is below a mean 
# REC = [] 
# for Item in list_test: 
#      rec.append (Item [ 'age' ]) 
# Print (REC) # list_test remove the values corresponding to all age 
#  
# the reversed sequence inversion 
# [1,2,3,4] = Test 
# Print (List (the reversed (Test))) # output: [. 4,. 3, 2,. 1] 
# Print (Test) # outputs: [. 1, 2,. 3,. 4] 
#  
# the ASCII code corresponding to the character output ord 
# POW two or three parameters can be filled 
#print (pow (2,3)) # 8 output, equivalent to the power of 2 of 3 
# Print (POW (2,3,3)) # 2 is output, equivalent to the third power of 2, then in addition to in modulo 3 
#  
# round decimal rounding off 
# Print (round (4,436)) output is #. 4 
#  
# slice slice stored slice (start, end, step) 
# L = 'Hello' 
# S1 = slice ( 3,5,1) sections to save # S1 
# Print (L [S1]) # output is 'lo', equal to L [3,5] 
#  
# the sorted order, and performs the process similar to the max min, default from small to large, of different types can not be sorted, which is essentially larger than the size 
# the sorted also possible introduction method 
# list_test = [ 
#      { 'name': 'Alex', 'Age': 40}, 
#      { 'name': ' ZJL ',' Age ': 28}, 
#      {' name ':' Zhao ','age':18},
#     { 'name': 'Kobe', 'Age': 40}, 
# ] 
# Print (List (the sorted (list_test, Key = the lambda DIC: DIC [ 'Age']))) 
#  
# SUM of iterables evaluated and 
# type view corresponding data type 
# VARS displayed when no local variable parameters, or all of the methods of the dictionary corresponding to an output 
# Print (VARS ()) # used when refilling detail 
# __impot__ importing files, can be imported string type , import can not be imported, but eventually import are introduced __import__

The following are a few simple document describes the entry operation:

# Reading a file, writing, and r + additional read-write mode (recommended browser: HTTPS: //www.cnblogs.com/linhaifeng/articles/5984922.html) 
# R & lt: read-only w: only write a: Append r +: readable and writable 

# read files test 
# F = Open ( 'test', 'R & lt', encoding = 'UTF-. 8') arranged to read the reference note # coding table 
# test_r reached, f.read = () # read the contents of the file 
# Print (test_r) 
# Print (f.readable ()) # view the file is readable return True 
#                        # file read only once from the front to the rear, appeared in front of f.read, the cursor is already here Finally, the document 
# Print ( 'the contents of the first line is:', (), end = 'f.readline') # line only reads the contents of the file, and the cursor down 
# Print ( 'second row content is: ', f.readline (), End =' ') 
# f.close () 

# write to file test 
# contents are written to the file must be a string, otherwise the system will error 
#f = open ( 'test', 'w', encoding = 'utf-8') # entered here if the file name exist in the priority list, the original file is overwritten 
#                                            # If there is a newly created file 
# Print (f.writable ()) # show whether the file can be written to return True 
# f.write ( 'the Hello world \ the n-') # write to 
# f.writelines ([ 'alex \ the n-', 'zhaolei leather look ',' zhoujielun \ n ', ' kobe ']) # looks like this is the only place it can be passed in the list 
# f.close () 

# operation append mode (often used as an access log records that can be used to access the site log) 
# Open = F ( 'Test', 'a', encoding = 'UTF-. 8') 
# Print (f.readable ()) returns a value of False # 
# f.write ( 'the second row change') append mode # can not read the file, the contents of the input file is added in the last 
# f.Close () 

# R & lt read-write mode + 
# F = Open ( 'Test', 'R & lt +', encoding = 'UTF-. 8')
# Print (f.readable ()) # can be read, returns True 
# Print (f.writable ()) # can be written, returns True 
# 
# Print ( 'the contents of the first line:', f.readline (), end = '') # read this time the cursor has moved to the second line 
# f.writelines ( 'skin at the front of the second row \ n') # why only read one line, it is added to the last writing surface it 
#                                       # write mode is directly covered 
# f.close () 

# with automatic opening and closing 
# writing format 
# with open ( 'Test', 'R & lt', encoding = 'UTF-. 8') aS F, \ 
#      Open ( 'text_new', 'W', encoding = 'UTF-. 8') AS D: 
#      test_l f.read = () 
#      Print (test_l) # f.read can not be printed directly, the pointer address appear

Sleep myself. . .

Guess you like

Origin www.cnblogs.com/xiaoyaotx/p/12399153.html