Python common functions

Source: Internet
Author: User

Tag: It's complex function address strong Col SSG Logs iterate object

Function (method) Function
Type ()
ID ()
List ()
Tuple ()
Dict ()
STR ()

1.type (): Accepts an object as a parameter and returns its type. Its return value is a type object.

>>> Type (123) #整数<class 'int'>>>> Type ('Hello,world') #字符串<class 'Str'>>>> Type (12.2+1j) #复数<class 'Complex'>>>> Type (12.3) #浮点数<class 'float'>
>>> type ([1,2,3,4])#List<class 'List'>>>> type ({'name':'Kebi',' Age': 28})#Dictionary<class 'Dict'>>>> type ((1,2,3,4))#Meta-group<class 'tuple'>>>> type (True)#Boolean type<class 'BOOL'>

Type () as a type function, you can detect the types of all data. Common data types: integers, long integers, floating-point numbers, complex numbers, ganso, lists, dictionaries, strings, and Booleans

The object above is known by its return value as the type of the object, and the return value is a type object.

>>> type (Type (4))
<class ' type ' >

2.id (): The memory address of the object can be viewed.

>>> a = 10>>> B = 12>>> ID (a)1731224064>>> ID (b)1731224128

3.list (): Convert an Iterative object to a list

>>> List ('wo shi ni baba') List of #字符串 ———— ['W','o',' ','s','h','I',' ','N','I',' ','b','a','b','a']>>> List ((1,2,3,4,5) ) #元祖 List of ————— [1, 2, 3, 4, 5]

When a dictionary is used as a parameter to a list (), the key is extracted to form a list

>>> List ({'name':'Kebi',' Age':' -'})['name',' Age']>>> List ({'name':'Kebi',' Age':' -','Sex':'Women'})['name',' Age','Sex']

4.STR (): Converts the Obj object to a string.

>>> STR (123)'123'>>> STR ([1,2,3,4])'[1, 2, 3, 4]'>>> Str (1,2,3,4,5))'(1, 2, 3, 4, 5)'>>> Str ({'name':'Kebi',' Age':' -'})"{' name ': ' Kebi ', ' age ': ' + '}"

5.tuple (): Converts an iterative object into a meta-ancestor object.

>>> Tuple ('Hello,word') #字符串 ———— "Yuan zu ('H','e','L','L','o',',','W','o','R','D')>>> tuple ([1,2,3,4]) #列表 ———— "Yuan zu (1, 2, 3, 4)

String (tuple)--"tuple--" (list)--"(join) string

List ()

>>> SSG = tuple ('Hello,word')>>>SSG ('H','e','L','L','o',',','W','o','R','D')>>>"'. Join (List (SSG))'Hello,word'

Python common functions

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.