#!/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