Knight Plan-python full stack 07 base data type Supplement

Source: Internet
Author: User

Meta-group

If there is only one data in the tuple, and there is no comma, the tuple is the same as the data type of the data inside.

# Tu = ("Alex")         #class strtu = (1)              # class   int#  tu = (True)             #class   boolprint(Type (TU))
List

The list can be added between the list

L1 = [== ['Alex','wusir'= L1 + L2  Print(L3)   #[1, 2, 3, ' Alex ', ' Wusir ']

 Note: When looping a list, dictionaries , it is best not to change the size of this list (additions and deletions) of the operation

Trap Question 1
#Delete data that is indexed as odd in the L1 listL1 = [11, 22, 33, 44, 55, 66, 77, 88]#method All slices plus step#del L1[::2]## Print (L1)#method Two backwards Delete#for I in range (len (L1), -1,-1):#if I%2 = = 1:#del L1[i]#print (L1)#method Three directly moves an even number out to the new list#L2 = list ()#For i in range (len (L1)-1):#if I% 2 = = 0:#l2.append (L1[i])#print (L2)

Quickly create a dictionary Fromkeys

DIC = Dict.fromkeys ([1,2,3],{"Alex"})print(DIC)      # {1: {' Alex '}, 2: {' Alex '}, 3: {' Alex '}}

Interview question: How to create a dictionary

1) dic = {}

2) dic = Dict ()

3) dic = Dict.fromkey (key, value) #如果没有值, default is None

Trap question Two
Dic1 = Dict.fromkeys ([],[])print(dic1) dic1[1].append ('Alex  ')print(dic1)       #print(ID (dic1[1)))  Print(ID (dic1[2)))print(ID (dic1[3)))
Conversion of data types
int STR BOOL Three conversions
str <---> bytes
STR <---> list

Dict.keys () dict.values () dict.items () list ()
Tuple <---> list
Dict---> List
string conversion to list split
# str---> List
# S1 = ' Alex Wusir taibai '
# L1 = S1.split ()
# print (L1)
# list ---> str the elements in this list are all str types
Convert list to String jion
# L1 = [' Alex ', ' Wusir ', ' Taibai ', 100]
# # s2 = '. Join (L1)
# # print (S2)

Knight Plan-python full stack 07 base data type Supplement

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.