Python data type

Source: Internet
Author: User

Data type ' "" There is no difference inside can add text # integer number: integer number # can be expressed as: Age ID number, telephone, QQ number age=10user_id=12321313213231231232131qq=666666666# String type: As long as the quotation marks contain the string type # can be used to represent: the name of gender Name= ' Egon ' #列表: Can hold multiple values, each value can be any data type # can hold multiple values, can be used to indicate: equipment, hobby # to take the elements in the list, you need to pass the subscript, Starting from 0 hobbies=[' Chouyan ', ' hejiu ', ' Tangtou ']>>> l=[1, ' A ',[2,3]]>>> l[1, ' a ', [2, 3]]>>> l[0] 1>>> l[1] ' a ' >>> l[2][2, 3]>>> l[2][0]2>>> l[2][1]3################ #字典: Using key: Value is stored in a way that can hold multiple values each value can also be any data type but key must be immutable data type dic={' name ': ' Egon ', ' Password ': ' 123 '}>>> dic={' name ': ' Egon ', ' Password ': ' 123 '}>>> ID (DIC) 48517336>>> type (DIC) <class ' dict ' >>>> dic{' Name ': ' Egon ', ' Password ': ' 123 '}>>> dic[' name '] ' Egon ' >>> dic[' password '] ' 123 ' >>> add key : valuedic[' count ']=2>>> dic[' count ']=2>>> dic{' name ': ' Egon ', ' Password ': ' 123 ', ' Count ': 2} Change value > >> dic[' name ']= ' Alex ' >>> dic{' name ': ' Alex ', ' password ': ' 123 ', ' Count ': 2} The value has changed, so it isVariable ####### #可变数据类型: (non-hash type) ID invariant type immutable value changed >>> l=[1,2]>>> ID (1) 1728427072>>> ID (2) 1728427104>>> type (L) <class ' list ' >>>> l.append (3) #append是往列表里加一个 >>> l[1, 2, 3] Immutable data type: The immutable type takes the int type as an example: actually i + = 1 is not really on the original int object +1, but instead re-creates an int object with value 6, I refers to this new object. >>> i = 5>>> i + = 1>>> I6 Verify the memory address of the variable i through the ID function (using hex (ID (i)) to see the memory address of the 16 binary) >>> i = 5&gt ;>> i + = 1>>> i6>>> ID (i) 140243713967984>>> i + = 1>>> i7>>> ID (i) 140243713967960 you can see that the memory address will change when i + = 1 o'clock is executed because the int type is immutable. Change the code, but the variable values of multiple int types are identical, to see if they have the same memory address. >>> i = 5>>> j = 5>>> ID (i) 140656970352216>>> ID (j) 140656970352216>>> k = 5& Gt;>> ID (k) 140656970352216>>> x = 6>>> ID (x) 140656970352192>>> y = 6>>> id (y) 140656970352192>>> z = 6>>> ID (z) 140656970352192 copy code for immutable type int, regardless of how many immutable types are created, as long as the values are the same, point to the same memory address. There are also short strings in the same situation. ############### #布尔类型 # judge the right and wrong ture,false>>> age=50>>> age > 100false>>> if Age > 100:print (' Wow,time to end ') >>> age=101>>> if age > 100:print ("Wow,time to End") Wow,time to end################ #################### #字符串切分 >>> msg= ' Egon|alex|wupeiqi|yuanhao ' >>> msg ' Egon|alex|wupeiqi|yuanhao ' >>> msg.split (' | ') [' Egon ', ' Alex ', ' Wupeiqi ', ' Yuanhao ']>>> user_name=msg.split (' | ') >>> user_name[' Egon ', ' Alex ', ' Wupeiqi ', ' Yuanhao ']>>> user_name[2] ' Wupeiqi ' >>> msg= ' Egon Alex Wupeiqi Yuanhao ' >>> msg ' Egon Alex Wupeiqi Yuanhao ' >>> msg.split () [' Egon ', ' Alex ', ' Wupeiqi ', ' Yuanhao ']>>> user_name1=msg.split () >>> user_name1[' Egon ', ' Alex ', ' Wupeiqi ', ' Yuanhao ']>> > user_name1[2] ' Wupeiqi ' #多引号实例 >>> msg= ' ' It's a nice day, it's sunny, I have no class this afternoon, ' ' >>> print (msg) It's a nice day, it's sunny. , I have no classes in the afternoon, #字符串的拼接 >>> msg1= ' hellow ' >>> msg2= ' world ' >>> msg3=msg1+msg2>>> msg3 ' Hellowworld ' >>> msg4=msg1*3>>> msg4 ' Hellowhellowhellow ' >>> Print (' Hellow ' + ' world ') hellowworld

  

Python data type

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.