① first have to go to the official website to download Python, the latest version of the current I do not clear. Download link http://www.python.org/downloads/. Launch the Python shell and start your Python journey right after the download is complete! ② here we introduce the Python data type but not much. Just emphasize that a Python variable is not defined by int, double, etc., but is used directly. and Matlab have a similar point. Here are two simple examples to understand
Age = #这里直接定义年龄为23 and then it's assumed to be an integral type.
name = ' CSDN ' # is also directly defined here, and then the default is the string
③ two types of formatted output modes
The first is to format the output string with the% operator
Code: Brand = ' CSDN '
name = ' Programmer '
Money = 199
Message = '%s ' is the aggregation place for%s, where the member is%d Yuan '% (Brand,name,money)
Print (message)
Run the above code in idle, the output is: CSDN is the programmer's gathering place, here the member is 199 yuan
The second way to format the output string using the format () method
Code: #直接一行语句搞定
Message = ' {0:s} is a gathering place for {1:s}, where the member is {2:D} meta '. Format (' CSDN ', ' Programmer ', 199) #这些代码的大小写有时不太准确, hope to understand.
Print (message)
Running this code on idle is consistent with the results above.
Type conversions in ④:python
There are three built-in functions in Python that let us do type conversions, they are int (), float (), and STR () function
the Int () function receives a floating-point or appropriate string
Eg:int (3.1415) #运行结果是3
Int (' 1314 ') #运行结果是1314
Int (' 3.123 ') #这种写法是错误的, please note.
the float () function receives an integer and an appropriate string
Eg:float #运行结果是23.0
Float (' 3.12313 ') #运行结果是3.12313
The str () function turns a number of integers or floating-point numbers into strings
EG:STR (1231) #运行结果是 ' 1231 '
STR (3.12315) #运行结果是3.12315
⑤ Some operations on the list
For example, age = [12,21,13,35,16,23] #其实这里面也可以放不同类型的数据
Lists can be changed, such as the addition and deletion of individual elements. We will introduce tuples later, which cannot be modified.
Here are some examples of the operations of the list
AGE[2] =13 #也可以这样访问列表中元素, similar to our array
Age[-1]=23 #也可以这样, in fact, negative numbers as from the end of the number, 1 refers to the penultimate element, 2 is the penultimate second.
Someage = Age[2:4] #输出结果为 [13,35] refers to the output of an element in the age list that is indexed from 2 to 4-1. Remember the output or the list
Someage = Age[0:5:2] #是从索引0到5 Each 2 access once this result is [12,13,16]
Del age[1] #用del去删除列表中索引为1的数, so the result is [12,13,35,16,23]
Age.append (' No fan of the program Dog ') #打印age列表, the result is [12,21,13,35,16,23, ' No fan of the program Dog '], remember that the list of different types of elements can be placed.
A summary of some of the basic points in Python: 0 Basics can also read the basics of Python