Describe
The Python Join () method is used to generate a new string from the elements in the sequence with the specified character connection.
Grammar
Join () method syntax:
Str. Join(sequence)
Parameters
- Sequence-the sequence of elements to concatenate.
return value
Returns a new string that is generated after the elements in the sequence are concatenated by specifying a character.
Instance
The following example shows how join () is used:
# !/usr/bin/python "-"= ("a" "B") "C"# string sequence print str.join (seq);
The result of the above example output is as follows:
A-b-c
Example 2:
forFieldinchObj._meta.fields:ifUpdate_fields is notNone andField.name not inchUpdate_fields:Continueproperty_name="'. Join (X.capitalize () forXinchField.name.split ('_')) Property_name= Property_name[0].lower () + property_name[1:] ifProperty_nameinchSrc_obj:value=Src_obj[property_name]ifValue is notNone andValue! ="': TP=type (field)ifTpinch(Integerfield, Bigintegerfield) andIs_int (value): SetAttr (obj, field.name, int (value))elifTpinch(Decimalfield,) andIs_decimal (value): SetAttr (obj, field.name, float (value))elifTpinch(Charfield,):#If it is a group, you need to merge the array ifisinstance (value, list): SetAttr (obj, field.name, u','. Join (Unicode (v) forVinchvalue)) Else: SetAttr (obj, Field.name, value[:field.max_length])elifTpinch(TextField,): SetAttr (obj, field.name, value)elifTpinch(Datefield,): SetAttr (obj, Field.name, datetime.datetime.strptime (value, Mtime_date_format)) elifTpinch(Datetimefield,): SetAttr (obj, Field.name, datetime.datetime.strptime (value, Mtime_datetime_forma T))elifTpinch(ForeignKey,): SetAttr (obj, field.name, value)returnObj
Python Join () method