#005 # do not declare the data type when assigning values to variables in python I = 33 print I # You can do this. the reason is that python regards everything encountered in the Program as an object (even int is no exception) # when using an
#001 # Python has the simplest "Hello World" syntax in the world # By The Way, this sentence is a comment Print 'Hello world! ' Print "Hello world! " Print" "Hello world! " Print ''' Hello world! ''' Print ''' note the quotation marks ''' on the
1. nameerror: access an unstated variable>>> VNameerror: Name 'V' is not defined
2. zerodivisionerror: the divisor is 0. >>> V = 1/0Zerodivisionerror: int division or modulo by zero
3. syntaxerror: syntax error >>> IntSyntaxerror: Invalid Syntax
I was finding that I needed a progress indicator for Linux and Windows console applications that cocould be used to show the user that work was progressing and how much of the total work that had been completed. I finally broke down and wrote this
First, let's talk about the closures in Python:
1. Function Nesting is required, that is, writing another function in a function.
2. An external function must return an internal function reference.
3. Some local variables exist in external functions,
# Fig. 2.13: fig02_13.py
# Displaying an object's location, type and value.
# Prompt the user for InputInteger1 = raw_input ("enter first INTEGER:/N") # Read a stringPrint "integer1:", ID (integer1), type (integer1), integer1# Print the identifier,
Source code download: here
#037 filename = '' while 1: filename = raw_input (" input a file name :") If filename = 'q': Break try: F = file (filename, 'R ') Print 'opened a file. ' alias T: Print 'there is no file named', filename # End
In a word dictionary, you only need to save the frequency of the part-of-speech of a word. In addition, considering that reading a dictionary into memory at a time consumes too much, you must divide the dictionary into multiple parts.
. To meet this
Python socketserver code record, which was excerpted from the Internet and rewritten by the customer's test end!
Server:
import SocketServerclass RequestHandler(SocketServer.StreamRequestHandler): def handle(self): while True: mdata = self.
Suppose you have a list in Python that looks like this:[
'A'
,
'B'
,
'A'
]
# Or like this:
[
1
,
2
,
2
,
2
,
3
,
4
,
5
,
6
,
6
,
6
,
6
]
And you want to remove all duplicates so you get this result:[
'A'
,
'B'
]
#
At the beginning, I learned python. Listen to the recommendations of senior colleagues and play with Python challenge.
Actually, you can use various languages, but when you finish reading others' answers, you will find how simple and elegant python
Similar to other programs on the Internet, a global replacement function is added here.
You can replace the entire document to perform global replacement operations such as translation and troubleshooting.
#-*-Coding: UTF-8 -*-
Import OS, types,
Instance attributes and class attributesTheoretical Basis
Class attributes are similar to static variables in C ++. You can directly access them through class name. attribute.
The instance attribute is the attribute that can be used only after the
_ Slots _ is used to restrict instance attributes in the class. Each instance object X has a dictionary X. _ dict __. python allows you to bind arbitrary attributes to X instances through this dictionary. defining a class attribute named _ slots _
The observer mode defines one-to-many dependencies between objects. When a topic object changes, the dependent objects will receive notifications and update automatically, the observer mode has two modes: 'push' and 'pull '. I implement the 'push'
Turn: http://ihipop.info/2010/10/1777.html
Python code
# Initialize a dict
>>> D = {'A': 1, 'B': 0, 'C': 1, 'D': 0}
# The intention is to traverse dict. If the element value is 0, delete it.
>>> For K in D:
... If d [k] = 0:
Exchange variable
x =6y =5 x, y =y, x print x>>> 5print y>>> 6
If statement in line
print "Hello" if True else "World">>> Hello
Connection
The last method below seems cool when binding two different types of objects.
fc =["Packers","49ers"]afc
In the programming process, you can learn more about the language and some skills, so that you can become a good programmer.
For Python programmers, pay attention to these things mentioned in this article.You can also take a look at Zen of Python
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