首页 > 技术文章 > Python 学习1

kingoscar 2016-09-27 07:03 原文

1.Python can only print out string. So if we have to convert all the non-string to string before print it out.

2.Objective Oriented Programming:Class,instance and objects. Instance can be treat as the type of students in the class(gender, team), which object is the strudents. Method is that a game which need to organize students from each instance(type of student). Moreover, this game has ability to modify of instance.

3. There are more than one ways(append()) to add items into a list. And a list can contain mutiple types of objects.

4. We use open() function to open a file. An open() function has two arguments: a. The file name. b. The mode of working with file.

5. Most data files use .csv format. And we user filename.read() to transfer data to certain variable.

6. The ways to split data is to use filename.split(","),the symbol in the double quotes is the symbol to split each elements in the target file.

  Attention:  There a set of data which include three elements, each element is divided by space. So the data set in .cvs file looks like this :

  Albuquerque,749

  Anaheim,371

  Anchorage,828

  So after we open() and read() the file. we split() them into the list with 3 elements. And store them into three_rows, it looks like this: 

  three_rows = ["Albuquerque,749", "Anaheim,371", "Anchorage,828"]

  If we want to saperate each element into name and number. we need to use split() again with the symbol comma. Then, the final list will look like this:

  final_list = [["Albuquerque","749"], ["Anaheim","371"], ["Anchorage","828"]]

 

推荐阅读