Resources:
1. Basic Python Tutorial
2. http://www.runoob.com/python/python-chinese-encoding.html
3. http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000
? assigning values to variables
Variables in Python do not need to be declared, and variable assignment operations are the process of declaring and defining variables.
Each variable must be assigned before it is used, and the variable will not be created until the variable is assigned. Examples are as follows:
# !/usr/bin/python # -*-coding:utf-8-*- # Assignment integer variable # floating-point "John"# String Print counterprint milesPrint name
Use the DEL statement in Python to delete single or multiple objects. The syntax is as follows:
del Var1[,var2[,var3[....,varn] []]
? assigning values to variables
Python has five standard data types:
- Numbers (number): Int,long,float and complex. Where the long type number at the end plus L differs from the int type.
- String (String)
- List (lists)
- Tuple (tuple)
- Dictionary (dictionary): A + BJ, or complex (a, b).
python string
String Usage instance:
#!/usr/bin/python#-*-coding:utf-8-*-Str='Hello world!'PrintStr#Output Full StringPrintSTR[0]#the first character in the output stringPrintStr[2:5]#A string between the third and fifth in the output stringPrintStr[2:]#outputs a string starting from the third characterPrintSTR * 2#output String two timesPrintSTR +"TEST" #string for output connection
python list
#!/usr/bin/python#-*-coding:utf-8-*-List= ['ABCD', 786, 2.23,'John', 70.2]tinylist= [123,'John']PrintList#Output Complete listPrintLIST[0]#the first element of the output listPrintList[1:3]#outputs the second to third elementPrintList[2:]#outputs all elements from the third start to the end of the listPrintTinylist * 2#output List two timesPrintList + tinylist#print a list of combinations
python tuples
#!/usr/bin/python#-*-coding:utf-8-*-tuple= ('ABCD', 786, 2.23,'John', 70.2) Tinytuple= (123,'John')PrintTuple#Output Full tuplePrintTUPLE[0]#the first element of an output tuplePrintTuple[1:3]#outputs the second to third elementPrintTuple[2:]#outputs all elements from the third start to the end of the listPrintTinytuple * 2#output tuple two timesPrintTuple + tinytuple#Print a group of tuples
python tuples
#!/usr/bin/python#-*-coding:utf-8-*-Dict={}dict[' One'] =" This is one"dict[2] =" This is the"tinydict= {'name':'John','Code': 6734,'Dept':'Sales'}Printdict[' One']#the value of the output key is ' one 'PrintDICT[2]#the value of the output key is 2PrintTinydict#output a complete dictionaryPrintTinydict.keys ()#Output All keysPrintTinydict.values ()#Output All Values
Python Basic Learning Note (i) Variable type