Python Summary 1

Source: Internet
Author: User

1. In __init__ (self, ...) In the initialization function, the properties of the object are defined, the attributes are not all written in parentheses, some properties of the initial value are assigned when the expression is defined in parentheses, and other properties that do not have an initial value can be
Directly unload the code block, self. Property name, just define it


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


3.datetime module, which has a DateTime class that defines the time, such as defining a Time object, When=datetime.datetime (2015,5,5,2,5,2), when the property inside the object is the date
, Time division seconds, you can display any property, print (When.year), so it shows the year, the DateTime module is also date,time these two small class, if only the relationship date is used date, if only care about seconds and minutes with the time class


4. Can also be decomposed, in the DateTime module there is also the date and time function, the object by calling these two functions to display the seconds or months of the day can be, when.date () or When.time ()


5. For subtracting a DateTime object we get another DateTime object


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


In 7.python, there are 3 built-in data structures: lists, tuples, and dictionaries.
1. "List"
A list is a data structure that handles a set of ordered items, that is, you can store a sequence of items in a list. Items in the list. The items in the list should be included in square brackets,
This way python will know that you are specifying a list. Once you have created a list, you can add, delete, or search for items in the list. Since you can add or delete items,
We say that the list is a mutable data type, that is, the type can be changed, and the list can be nested.


2. "Tuples"
Ganso and lists are very similar, but tuples are immutable. That is, you cannot modify tuples. Tuples are defined by a comma-delimited list of items in parentheses. Tuples are typically used when a statement or user-defined function can safely take a set of values, that is, the value of the tuple being used does not change. Tuples can be nested.




3 "Dictionary"
The dictionary is similar to the Address book where you find the address and contact details by contact name, i.e. we associate the key (first name) with the value (details). Note that the key must be unique, as if two people happen to have the same name, you cannot find the correct information.
Key-value pairs are tagged in the dictionary in such a way that: 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 braces. Also, remember that the key/value pairs in the dictionary are not sequential.
If you want a particular order, then you should sort them yourself before using them.


8. For the use of functions, when passing parameters, if we pass a variable to a parameter, then this passes the object corresponding to the variable, not the ' variable itself ', if the variable represents the object, that is,
His corresponding value or list of objects, such as a variable, such as: Lists and so on, the list can be increased, reduced, deleted to do these changes, then the function can change the value of the variable, if it is a number, letters, etc.
, these objects cannot be modified, so the function is called, but the variable cannot be modified because the object she corresponds to cannot be modified.


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


10.in in Python can be either a keyword or a function of an operator


11. In the function, there is a default value parameter, when the function is called, if the default value is an immutable object or type, such as a character or a number, then in multiple calls, this parameter does not have memory ability, but if
The default value of this parameter is variable, for example, a list, then the next time you call this function, if you have not given the parameter an argument, that is, the default value, then the default value will change, the parameter
There's going to be memory.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Python Summary 1

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.