Python-day3 knowledge points--depth copy, function basic definition, built-in function

Source: Internet
Author: User
Tags arithmetic operators shallow copy

A. Depth copy

Import copy# Shallow copy n1={' K1 ': ' Wu ', ' K2 ': 123, ' K3 ': [' Carl ', 852]}n2=n1n3=copy.copy (n1) print (ID (n1)) ' Print (ID (n2)) ' Print (ID (n3)) Print (ID (n1[' K3 '))) print (ID (n3[' K3 ')) #深拷贝n4 =copy.deepcopy (n1) print (ID (n4)) print (ID (n1[' K3 ')) Print (ID (n4[' K3 ') ]))

return value: 1078765610787656115328482027768820277688114550642027768820276328

Two. Basic definitions of functions

1. Default parameters:

Def Mail ():d EF func (name, age = 18): # Specifies the parameter print "%s:%s"% (name,age) # using default parameters func (' Alex ') func (' Wupeiqi ', 19)

2. Dynamic parameter sequence:

def func (*args): Print args# execution mode one func (11,33,4,4454,5) # execution mode two li = [11,2,2,3,3,4,54]func (*li)

3. Dynamic Parameter dictionary:

def func (**kwargs): Print args# execution mode one func (name= ' Wupeiqi ', age=18) # execution mode Two li = {' name ': ' Wupeiqi ', age:18, ' gender ': ' Male '} Func (**li)

4. Sequence and Dictionary:

Def show (*arg,**kwargs):p rint (Arg,type (ARG)) print (Kwargs,type (Kwargs)) Show (64,56,99,w=76,p=33)

5. Use dynamic parameters to format strings:

S1 = "{0} is {1}" l=[' Alex ', ' SB ']result=s1.format (*l) print (result) S1 = "{name} is {a}" Result=s1.format (Name= ' Helen ', a= Print (Result) S1 = "{name} is {a}" d={"name": "Helen", ' a ': +} #result =s1.format (name= ' Helen ', a=19) Result=s1.format ( **D) print (result) 6.LAMBDA expression

6.lambda expression:

Lambda expression equals simple function Expression def func (a): B=a+1return b equals Func=lambda a:a+1ret=func (5) print (ret)

Three. Built-in functions

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7F/3D/wKioL1cXYUvwwoHxAACw79ePA-s673.png "title=" Clipboard1.png "alt=" Wkiol1cxyuvwwohxaacw79epa-s673.png "/>abs () absolute value

All () True if the incoming object element is true (NOT null)

Any () One true is True

ASCII () When non-ASCII codes are encountered, characters such as \x,\u or \u are output to indicate

Example:print (ASCII (TEN), ASCII (9000000), ASCII (' b\31 '), ASCII (' 0x\1000 ')) return result: 9000000 ' b\x19 ' [email protected] ‘

Bin () binary conversion

ByteArray () string conversion array

Callable () Determines whether an object can be called

Chr () number to ASCII

Ord () ASCII converts to numbers, Write verification code with

Compile () string converted to Python code

#!usr/bin/env Python#coding:utf-8 namespace = {' name ': ' Wupeiqi ', ' Data ': [18,73,84]} code = ' Def hellocute (): Return "n Ame%s, age%d "% (Name,data[0]," "func = Compile (code, ' <string> '," exec ") exec func in namespace result = Nam espace[' Hellocute '] () print result

Complex () negative number

Delattr/getattr/setattr/hasattr () for reflection

Dictionary () Creating a dictionary

Divmod ()

English Description:

The Divmod (A, B) method returns a a//b (division rounding) and a to B remainder

Returns a result type of tuple

Parameters:A, B can be a number (including plural)Version:

It is not allowed to deal with complex numbers before the python2.3 version, so let's pay attention.

English Description:

Take the non complex numbers as arguments and return a pair of numbers consisting of their quotient and remainder when u Sing Long division. With mixed operand types, the rules for binary arithmetic operators apply. For plain and long integers, the result is the same as (A//b, a% b). For floating point numbers the result was (q, a% b), where q is usually Math.floor (A/b) but could be 1 less than that. In any case Q * b + a% B are very close to a, if a% B is non-zero it had the same sign as B, and 0 <= abs (a% B) < ABS (b).

Changed in version 2.3:using Divmod () with complex numbers is deprecated.

Enumerate () is used to traverse elements in a sequence and their subscripts

Map () The first parameter receives a function name, and the second parameter receives an object that can iterate

Filter () Filtering

Float ()

Format ()

Frozenset () Freeze Collection

Globals () Global variables

Hash () Dictionary key hashes

Hex () calculates hex

Locals () Local variables

Memoryview ()

Oct () octal conversion

POW () Power operation

Range () iterator

Round () rounding

Slice () slices

Sorted () sort

STR ()

SUM () sum

Super () executes the parent class

Dir () returns key

VARs () returns the key value pair

Zip () List compression

This article from "Life, such as painting, Pen no regrets!" "Blog, be sure to keep this provenance http://521angela.blog.51cto.com/9680035/1765942

Python-day3 Knowledge points--depth copy, function basic definition, built-in function

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.