Python rookie diary 1, python dish Diary

Source: Internet
Author: User

Python rookie diary 1, python dish Diary
1. in _ init _ (self ,...) in the initialization function, define the attributes of the object. These attributes do not need to be written in brackets. when defining the attributes in parentheses, You need to assign some attributes of the initial value, and other attributes without the initial value. You can
Unmount the code block directly, and define the self. attribute name in this way.


2. random. randint (n, m) returns the value between n and m, and includes m, while range (n, m) does not include m.


3. datetime module, which has a datetime class. This class is used to define time. For example, to define a time object, when = datetime. datetime (,). The attributes in the when object are year, month, and day.
, Time, minute, second, can display any attribute at will, print (when. year), this shows the year. The datetime module also contains the date and time sub-classes. If only the date is related, the date is used. If only the time and second are concerned, the time class is used.


4. it can also be decomposed. In the datetime module, there are also date and time functions. The object can display the time, minute, second, year, month, and day by calling these two functions. date () or when. time ()


5. For the subtraction of A datetime object, we get another datetime object.


6. 30 keywords in python: and, del, for, is, raise, assert, elif, from, lambda, return, break, else, global, not, tyr, class, limit t, if, or, while, continue, exec, import, pass,
Def, finally, in, print, yield


7. python has three built-in data structures: List, tuples, and dictionary.
1. [LIST]
List is the data structure that processes a group of ordered projects. You can store a series project in a list. Project in the list. The items in the list should be included in square brackets,
In this way, python knows that you are specifying a list. Once you create a list, you can add, delete, or search for projects in the list. Because you can add or delete projects,
The list is a variable data type, that is, this type can be changed and the list can be nested.


2. [tuples]
The ancestor is very similar to the list, but the tuples are immutable. That is, you cannot modify the tuples. The tuples are defined by commas (,) in parentheses. Tuples are usually used to securely use a group of values for statements or user-defined functions. That is, the values of the used tuples do not change. Tuples can be nested.




3 [dictionary]
The dictionary is similar to the address book in which you use the contact name to find the address and contact details. That is, we associate the key (name) and value (details) together. Note that keys must be unique, as if two people happen to have the same name, you cannot find the correct information.
Key-value pairs are marked in the dictionary in this way: d = {key1: value1, key2: value2 }. Note that their key/value pairs are separated by colons, and each pair is separated by commas, all of which are included in curly brackets. Remember that the key/value pairs in the dictionary have no order.
If you want a specific sequence, you should sort them before use.


8. for function usage, when passing a parameter, if we pass a variable to a form parameter, this will pass the object corresponding to the variable, rather than the 'variable ', if the variable represents an object, that is
Objects such as their values or lists are variable, such as lists. The list can be increased, reduced, or deleted to make these changes, then the function can change the value corresponding to this variable, for example, numbers, letters, and so on.
These objects cannot be modified, so even if the function is called, the variable cannot be modified because the corresponding object cannot be modified.


9. The function body in the def statement can contain one or more return statements.


10. in python can be a keyword or operator.


11. in a function, if the default value is an unchangeable object or type, such as a character or number, when a function is called for multiple times, this parameter has no memory, but if
The default value of this parameter is variable. For example, if the list parameter is not provided, the default value is used when the function is called next time, the default value will change.
Capable of memory

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.