Scenario Description:The JSON module in the Python standard library integrates the ability to serialize data, and when serializing data using the Json.dumps () method, if there is a datetime data type in the target data, Will throw an
# local variables, only variables in the function body can be called def Fun (): = 234 print(a) # global variables, declared outside the body of a function, can be called in the body of a function ' GYC ' def Fun (): = 234 Print(
Introduced:This article is for the study of Python notes on December 27, 2016.Directory:
Regular expressions
Concept
Basic syntax
Match format
Commonly used 5 kinds of operation
Character matching
There is a simple rule of thumb to the tell == -you-use or is .
==is for value equality. Use it when you would like to know if both objects have the same value.
isis for reference equality. Use it when you would like to know
Reprint Address: http://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/As you may have heard, the function with yield is called generator (generator) in Python, what is generator?Let's throw away the generator and show the concept of
The first thing to make clear is that Python's dict itself cannot be sorted and more explicitly expressed as "a list of dict through operations into value ordered"There are several ways to do this:1.Import= {1:2, 3:4, 4:3, 2:1= sorted (X.items (),
Brief key points when a function passes a parameter:1, the parameter is passed through the automatic assignment of the object to the local variable name to achieve. The function parameter is only an instance of Python assignment in practice. Because
ConceptIn Python, an object assignment is actually a reference to an object. There are generally three ways to copy:
Direct Assignment
Shallow copy
Deep copy
DifferenceDirect assignment: A reference to the passed object, both
First, use Help (Zip) to see the documentation:It means that it returns an element that is a tuple of the list, the first element of a tuple by the original sequence 1 i.e. seq1[0], sequence 2seq2[0],.... Composed of a second element tuple by seq1[1]
During the Christmas period, I looked at the python for loop. Just practice, on a whim, wrote a small program of the Christmas tree. For Gentlemen a happy!The following code is attached:#coding: Utf-8import sysdef christmas (h): print ' \033[
There are several types of data that are used directly for a For loop:1. Data type of collection class: List tuple dict set STR, etc.2. Generator generator, including generator and generator function with yiledThese objects, which can be used
Generate 20 random files, the file name may be duplicated because no hash name is usedThere are 30-50 sequences in each fileEach sequence has a length of 70-120 baseimport osimport randomimport stringprint (dir (string)) Letter = string.ascii_
Character encoding
1, Python 2.x by default is ASCII encoding does not support Chinese, so when the code is in Chinese, you need to add #coding=utf-8 to the top line of the file. Python 3.x does not have this problem.
Variable naming
1. Create a Django Project
Use django-admin.py startproject mydjangosite reference here
2. Build a View
From django.http import httpresponsedef Hello (Request): Return HttpResponse ("My first simple Python Django project. ")3, modify the
Python Dictionary (Dictionary)
A dictionary is another mutable container model, and can store any type of object, such as another container model.
A dictionary consists of a pair of keys and corresponding values. Dictionaries are also referred to as
10/24For python, everything is an object, objects are created based on the class, and all the functions of the object are found in the class.
Variable name = Object (value) Duplicate function creates a class, and then the object goes to
#!/usr/bin/python# encoding: utf-8# -*- coding: utf8 -*-"" "Create Date: 2016/12/26Create Time: 17:53show Windows or Linux network Nic status, such as mac address, gateway, ip address, etc# python getnetworkstatus.pyrouting gateway:
Big data of Children's shoes often write timed task run data, due to the dependencies between tasks (generally downstream dependent on upstream data output), so often lead to data acquisition failure, because many people find that data failureWill
Modify the default Python version.Python default version Modification
When multiple versions of Python are installed on the computer, and the default Python version in Shell is not what you want, you need to modify the default version of Python.
Install Python 3.5 and django 1.8 on Windows 7, pythondjango
Reference: http://www.runoob.com/django/django-first-app.html
1. Download and install python 3.5.
You can customize the installation location and check the environment variable
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