.__delitem__) (Self,key) deletes the value of the given key (key) c.__missing__ (Self,key) Given a key if the dictionary does not exist, a default value is provided
(2) Simple customizationImplement init(),str(),repr(), etc.Print uses the str() method, and the real string object represents the use of the repr() method.
#! /usr/bin/env python
class Roundfloatmanual (object):
def __init__ (self,val):
ass
(_maintype, _subtype, **_params)The base class for all MIME classes, which are subclasses of the Email.message.Message class.
3. Class Email.mime.multipart.MIMEMultipart ()
In the 3.0 version of the email module (Python 2.3-python 2.5), this class is located in email. Mimemultipart.mimemultipart.This class is a direct subclass of Mimebase, which is used to generate MIME objects that contain multiple part
Python-python interpreter execution, python-python
Recently, due to the need of the company, I have been familiar with the magic language of python, which gives me the feeling that development is fast and the code is concise.
Let's start by listing the differences between th
Python Learning 1, python Learning
1. Introduction to python
Introduction to Python on various websites
Python is powerful... and fast;
Plays well with others;
Runs everywhere;
Is friendly easy to learn;
Is Open.
2. python vers
This article mainly introduces python exception-related information and sorts out relevant exception information. if you need it, you can refer to it recently. a small project may encounter Python exceptions, which is a headache, therefore, sort out exceptions to avoid confusion next time. The following describes how to organize Python exceptions.
1.
character in a game. Initial level: Level=1, after a period of time to upgrade: level=106.2 Declaration and reference of variables#!/usr/bin/env pythonname= ' Egon ' #变量的声明Name #通过变量名, the value of the reference variablePrint (name) #引用并且打印变量名name对应的值, ie ' Egon '6.3 Identifier Command specification:
Variable names can only be any combination of letters, numbers, or underscores
The first character of a variable name cannot be a number
The following keywords cannot be de
Introduction to code Debugging Using unit testing in Python programming, and python Unit Testing
For new programmers, one of the most common confusions is the topic of testing. They vaguely think that "unit testing" is good, and they should also do unit testing. But they do not understand the true meaning of the word. If it sounds like you, don't be afraid! In this article, I will introduce what unit testin
(_ maintype, _ subtype, ** _ params)The base class of all MIME classes, which is a subclass of the email. message. Message class.
3. class email. mime. multipart. MIMEMultipart ()
In the email module (Python 3.0-Python 2.3) of version 2.5, this class is located in email. MIMEMultipart. MIMEMultipart.This class is a direct subclass of MIMEBase. it is used to generate MIME objects of mail bodies containing m
statement, whether or not there is an exception, will normally close the file, it is not very good
Copy Code code as follows:
>>> Import syslog
>>> Try:
... f = open ("/root/test.py")
... except ioerror,e:
... Syslog.syslog (syslog. Log_err, "%s"%e)
. else:
... Syslog.syslog (syslog. Log_info, "no exception caught\n")
... finally:
>>> F.close ()
You see, we have the above example to use the try,except,else,finally these four clauses! :-), isn't it funny
Python3.5, and all subsequent code runs in this environment.Iii. Variable 1. Declare Variables
#!/usr/env python# -*- coding:utf-8 -*-name = "xiaoming"
The code above declares a variable named: name. The value of the variable name is: "xiaoming"2. Variable assignment
name = "xiao ming" name2 = nameprint(name,name2) name = "xiao hua" print("What is the value of name2 now?"name,name2)III. Rule for defining variable names:
1. Variable names can only be
path to my code is E: \ python_script \ day1.
Go to the directory and run the code
Execute with python2
Execution error
Because the default python2x encoding is ascii, Chinese characters are not supported.
Add
#-*-Coding: UTF-8 -*-
Run the command again.
If a problem occurs when python is executed after python is installedYou can uninstall and reinstall all python
: "wupeiqi"The role of a variable: a nickname that refers to what is stored in an address in memoryRules for variable definitions:
Variable names can only be any combination of letters, numbers, or underscores
The first character of a variable name cannot be a number
The following keywords cannot be declared as variable names[' and ', ' as ', ' assert ', ' break ', ' class ', ' Continue ', ' def ', ' del ', ' elif ', ' else ', ' excep
indicates that if the script is written to the/usr/bin/python directory, python will execute your script. In this way, the portability of writing programs is poor. If the python command in this path does not exist, an error is returned.Therefore, the first method is usually used.2. 1 byte = 8 bits
3. variable naming rules
Variable names can only be any comb
identifiers
The first character must be a letter in the alphabet or an underscore ' _ '.
The other parts of the identifier are composed of letters, numbers, and underscores.
Identifiers are case sensitive.
Can exist in Chinese identifiers
python reserved wordReserved words are keywords, and we cannot use them as any identifier names. Python's standard library provides a keyword module that can output all the keywords for the
This article mainly introduces an example of the Array usage of Python data structures. it describes the common usage of Array in detail and has good reference value, for more information about the Array usage of python data structures, see the examples in this article. The specific method is as follows:
import ctypes class Array: def __init__(self, size): asse
information. Therefore, we have another method.Assertions
Where print is used for viewing, assert can be used instead:
# err.pydef foo(s): n = int(s) assert n != 0, 'n is zero!' return 10 / ndef main(): foo('0')
Assert means expression n! = 0 should be True. Otherwise, an error will occur in the subsequent code.
If the a
Baptism soul, practice python (5) -- python operator, built-in function, python -- python
Previously, we mentioned the concept of BIF (built-in function). What is a built-in function? It is a function that has been defined by python. It can be used directly without being ma
The path to a Python guru [1] first understanding of python, first understanding of the path to python
Python Introduction
1: Founder of Python
Python /), it is an advanced programming language for interpreting, obj
Recently, to do a small project often encounter python anomalies, people are very headache, so the exception to the collation, to avoid the next encounter abnormal at a loss, the following is the collation of Python exception.
1.Python Exception Class
Abnormal
Describe
Nameerror
Try to access a variable that is not declared
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.