Python: 6 kinds of standard data types

Source: Internet
Author: User

#!/usr/bin/python3#basic syntax and data types for Python#a row in Python3 has multiple statements, separated by semicolons (;)Print("AAA") ;Print("BBB")#basic Data types, removing long typesPrint(type (1))Print(type (1.0))Print(type ("Str"))#allow multiple variables to be assigned continuouslyA=b=c=1Print(a,b,c) a,b,c=1,2,"BB"Print(a,b,c)#6 kinds of standard data types#number (numeric)#string (string)#List (lists)#tuple (tuple)#sets (collection)#Dict (dictionary)#number (numeric)#supports int float bool Complex (plural)#Numerical calculationPrint("5+3=", 5+3)Print("5-3=", 5-3)Print("5*3=", 5*3)Print("divide to get floating point number 2/4=", 2/4)Print("Division gets integer 2//4=", 2//4)Print("take the surplus 10%3=", 10%3)Print("exponentiation 4**2=", 4**2)Print("prescribe 4**0.5=", 4**0.5)#string (string)#the element is immutablestring="ABCDEFG"Print(string)Print(string[0])Print(string[0:-1])#from Beginning to EndPrint(string[2:])#starting from subscript 2 to tailPrint(string[2:4])#from subscript 2 to n-1 [m,n]Print(string*2)#Output 2 times#List (lists)#element-variablelistdemo=["AA", 1,"BB", 2]Print(listdemo)Print(listdemo[0])#output Subscript 0Print(listdemo[2:])#starting from subscript 2 to tailPrint(listdemo[1:3])#from subscript 2 to n-1 [m,n]Print(listdemo*2)#Output 2 timeslistdemo[0]="replaced by"Print(listdemo)#after the modified#tuple (tuple)#the element is immutableTupledemo= ("AA", 1,"BB", 2)Print(tupledemo)Print(tupledemo[0])#output Subscript 0Print(tupledemo[2:])#starting from subscript 2 to tailPrint(tupledemo[1:3])#from subscript 2 to n-1 [m,n]Print(tupledemo*2)#Output 2 timesTupledemo=()#Empty tupletupledemo= (a,)#a single elementPrint(tupledemo)#Set (set)#a sequence that is unordered and non-repeatablesetdemo={"a","b","C"}Print("set a", Setdemo)#set can do intersection and set differencesetdemo2={"a","b"}Print("Collection B", SetDemo2)Print("differential set of AB", setdemo-SetDemo2)Print("Ab's Set", setdemo|SetDemo2)Print("the intersection of AB",setdemo&SetDemo2)Print("the non-simultaneous existence of AB", setdemo^SetDemo2)#Dictionarydictdemo={"Tom":" -","Jerry":" the"}Print(dictdemo)Print(dictdemo["Tom"])Print("keys:", Dictdemo.keys ())Print("Values", Dictdemo.values ())#remove key to return valuePrint("Remove Tom", Dictdemo.pop ("Tom"))Print(dictdemo)#python common data Transformations" "int (x) str (x) tuple (s) Converts a sequence to a Narimoto group list (s) to convert a sequence into a list" "#comments for PythonPrint("Single-line Comment #")Print("Multiline Comment Single quotation mark (3 ')")Print("Multiline Comment Double quotation mark (3 double quotes)")

Python: 6 kinds of standard data types

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.