Stupid way to learn Python (3)

Source: Internet
Author: User

Exercise: Functions and files

seek()的用法:

>>> f.readlines()#读取出文件的所有内容

[‘abcdefghijk\n‘]

>>> f.seek(2) #将当前的位置设定为相对当前位置的2的位置。

>>> f.read(4) #读取4个位置的数据(从设定的位置开始读取,也就是ab 后面的四个字符)

‘cdef‘

>>> f.seek(2,1)#将当前的位置(2)设定为相对当前位置的2的位置。

>>> f.read(4)# 在读取四个位置的数据

‘ijk\n‘

>>> f.seek(2,2)

>>> f.read(4)

‘‘

>>> f =open(r"c:\input.txt","r")

>>> f.readlines()#将当前的位置设定为相对当前位置的2的位置。

[‘abcdefghijk\n‘]

>>> f.seek(2,0)#将当前的位置设定为相对当前位置的2的位置。

>>> f.read(4)#读取4个位置的数据(从设定的位置开始读取,也就是ab 后面的四个字符)

‘cdef‘

>>> f.seek(2,1)#将当前的位置(2)设定为相对位置的2的位置,也可以是负值,赋值是向前移动。

>>> f.read(4#再读取四个位置的数据

‘ijk\n‘

>>> f.seek(-2,2)#将当前的位置设定为相对文件结束为-2的位置,就是距离文件结束还有两个位置

>>> f.read(2) #读取二个位置的数据

‘\n‘

>>>

Every time you run F.seek (0) You go back to the beginning of the file, the code inside the ReadLine () scans every byte of the file until it finds one \ n, and then it stops reading
File, and returns the contents of the previous file.

Exercise: function can return something

Exercise: What have you learned so far?

Exercise: reading code

Exercise : more Practice

Exercise: More and more practice

The pop () function removes an element from the list (the last element by default) and returns the value of the element, the original list being deleted.

Exercise: Congratulations, you can take the exam now!

Exercise: Remembering logical relationships

Exercise : boolean expression exercises

Exercise: if (IF)

Exercise: Else and If

If more than one elif chunk is True, what does Python do with it?
Python only runs the first chunk that it encounters with true, so only the first chunk that is true will be
Run.

Exercise: Making a decision

Exercise: Loops and Lists

The range () function starts from the first number to the last, but does not contain the last number.

What is the function of Elements.append ()?
Its function is to append elements to the end of the list.

Exercise: While loop

Exercise: Accessing the elements of a list

Exercise: Branching and functions

Exit (0) What is the function?
In many types of operating systems, "exit (0)" Can interrupt a program, and the numeric parameters are used to denote the process
Whether the order was interrupted by an error encountered. Exit (1) indicates that an error has occurred, and exit (0) indicates that the program is normal
Exit the.

Exercise: Design and commissioning

Exercise: Review various symbols

Exercise: List of operations

Exercise: A dictionary, a lovely dictionary

Exercise: modules, classes, objects

Exercise: Birds of a Feather

Exercise: objects, classes, and dependencies

Exercise: Gordon, from Planet 25th, Percal.

Exercise: Inheritance (inheritance) VS compositing (composition)

Super () and __init__ use
The most common use of super () is in the __init__ function of the base class. Usually this is the only place where you can do this,
Here you do something in the subclass and then do the initialization of the parent class. Here is an example of completing the above behavior in child
Child
Class Child (Parent):

def __init__ (self, Stuff):
Self.stuff = Stuff
Super (Child, self). __init__ ()

Exercise: You make a game

Exercise: A skeleton of a project

Exercise: Automated Testing

Exercise: more complex user input

Exercise: Creating sentences

Exercise: Your first website

Exercise: getting input from the browser

Exercise: Create your Web game

Select a project, read through its documentation and easy tutorials. During the reading process, write the code in the document yourself and let them operate
Yes. I learned this way, in fact, every programmer is doing so. After reading the tutorials and documentation, try writing something.
Come out. Write anything, even if it is written by others can be, as long as the things can be done.

After finishing this book, start the next journey immediately!

Stupid way to learn Python (3)

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.