身份证号码编码规则及校验位校验算法

算法地址:http://jingyan.baidu.com/article/7f41ececff944a593d095c8c.html

简单验证长度

         /// <summary>
/// 检查身份证基本信息
/// </summary>
/// <returns>结果</returns>
private string CheckAndParse()
{
if (string.IsNullOrWhiteSpace(this.Id))
{
return "身份证号码不能为空";
}
if (this.Id.Length == )
{
return this.ParseCardInfo15();
}
if (this.Id.Length == )
{
return this.ParseCardInfo18();
}
return "身份证号码必须为15位或18位";
}

简单验证

身份证分为2中 18位 OR 15位

验证先用正则表达式进行初步验证 并且取出 身份证上面包含的信息(地区 生日 随机码 性别 尾号)

18位身份证

        /// <summary>
/// 18位身份证
/// </summary>
/// <returns>结果</returns>
private string ParseCardInfo18()
{
const string CardIdParttern = @"(\d{6})(\d{4})(\d{2})(\d{2})(\d{2})(\d{1})([\d,x,X]{1})";
Match match = Regex.Match(this.Id, CardIdParttern);
if (match.Success)
{
this.areaCode = match.Groups[].Value;
string year = match.Groups[].Value;
string month = match.Groups[].Value;
string day = match.Groups[].Value;
this.birthCode = year + month + day;
this.randomCode = match.Groups[].Value;
this.sexCode = char.Parse(match.Groups[].Value);
string verifyCode = match.Groups[].Value.ToUpper(); if (this.ValidateVerifyCode(this.Id.Substring(, ), char.Parse(verifyCode)))
{
try
{
this.Birth = BirthDate.GetBirthDate(year, month, day);
this.Area = AreaCodeMapping.GetArea(this.areaCode);
Sex = GetSex(this.sexCode);
}
catch (System.Exception ex)
{
return ex.Message;
}
return string.Empty;
}
}
return "身份证号码格式错误";
}

18位

15位身份证

         /// <summary>
/// 15位身份证
/// </summary>
/// <returns>结果</returns>
private string ParseCardInfo15()
{
const string CardIdParttern = @"(\d{6})(\d{2})(\d{2})(\d{2})(\d{2})(\d{1})";
Match match = Regex.Match(this.Id, CardIdParttern);
if (match.Success)
{
this.areaCode = match.Groups[].Value;
string year = match.Groups[].Value;
string month = match.Groups[].Value;
string day = match.Groups[].Value;
this.birthCode = year + month + day;
this.randomCode = match.Groups[].Value;
this.sexCode = char.Parse(match.Groups[].Value); try
{
this.Area = AreaCodeMapping.GetArea(this.areaCode);
this.Birth = BirthDate.GetBirthDate(year, month, day);
Sex = GetSex(this.sexCode);
}
catch (System.Exception ex)
{
return ex.Message;
}
return string.Empty;
}
return "身份证号码格式错误";
}

15位

校验代码

 namespace Notify.Solution.Code.IdentityCard
{
/// <summary>
/// 验证类
/// </summary>
public class Validator
{
/// <summary>
/// 验证码
/// </summary>
private readonly char[] verifyCodeMapping = { '', '', 'X', '', '', '', '', '', '', '', '' }; /// <summary>
/// 地区代码
/// </summary>
private string areaCode; /// <summary>
/// 生日
/// </summary>
private string birthCode; /// <summary>
/// 随机
/// </summary>
private string randomCode; /// <summary>
/// 性别
/// </summary>
private char sexCode; /// <summary>
/// Initializes a new instance of the <see cref="Validator"/> class.
/// </summary>
/// <param name="id">Id</param>
public Validator(string id)
{
this.Id = id;
this.Success = false;
this.ErrorMessage = string.Empty;
this.Area = null;
this.Birth = BirthDate.Empty;
this.Sex = Sex.Male;
} /// <summary>
/// 身份证ID
/// </summary>
public string Id { get; private set; } /// <summary>
/// 结果
/// </summary>
public bool Success { get; private set; } /// <summary>
/// 错误信息
/// </summary>
public string ErrorMessage { get; private set; } /// <summary>
/// 区域信息
/// </summary>
public AreaInformation Area { get; private set; } /// <summary>
/// 生日
/// </summary>
public BirthDate Birth { get; private set; } /// <summary>
/// 性别
/// </summary>
public Sex Sex { get; private set; } /// <summary>
/// 执行比较结果
/// </summary>
/// <returns>结果</returns>
public bool Execute()
{
string msg = this.CheckAndParse();
if (string.IsNullOrWhiteSpace(msg))
{
this.ErrorMessage = string.Empty;
this.Success = true;
}
else
{
this.ErrorMessage = msg;
this.Success = false;
}
return this.Success;
} /// <summary>
/// IdentityCard18
/// </summary>
public string IdentityCard18
{
get
{
if (string.IsNullOrWhiteSpace(this.Id))
{
return "身份证号码不能为空";
}
if (this.Success && this.Id.Length == )
{
return this.ToCardInfo18();
}
return this.Id;
}
} /// <summary>
/// ToCardInfo18
/// </summary>
/// <returns>结果</returns>
private string ToCardInfo18()
{
string bodyCode = GetBodyCode(this.areaCode, "" + this.birthCode, this.randomCode, this.sexCode);
char verifyCode = this.GetVerifyCode(bodyCode);
return bodyCode + verifyCode;
} /// <summary>
/// 获取bodyCode
/// </summary>
/// <param name="areaCode">areaCode</param>
/// <param name="birthCode">birthCode</param>
/// <param name="randomCode">randomCode</param>
/// <param name="sexCode">sexCode</param>
/// <returns></returns>
private static string GetBodyCode(string areaCode, string birthCode, string randomCode, char sexCode)
{
return areaCode + birthCode + randomCode + sexCode.ToString();
} /// <summary>
/// 检查身份证基本信息
/// </summary>
/// <returns>结果</returns>
private string CheckAndParse()
{
if (string.IsNullOrWhiteSpace(this.Id))
{
return "身份证号码不能为空";
}
if (this.Id.Length == )
{
return this.ParseCardInfo15();
}
if (this.Id.Length == )
{
return this.ParseCardInfo18();
}
return "身份证号码必须为15位或18位";
} /// <summary>
/// 18位身份证
/// </summary>
/// <returns>结果</returns>
private string ParseCardInfo18()
{
const string CardIdParttern = @"(\d{6})(\d{4})(\d{2})(\d{2})(\d{2})(\d{1})([\d,x,X]{1})";
Match match = Regex.Match(this.Id, CardIdParttern);
if (match.Success)
{
this.areaCode = match.Groups[].Value;
string year = match.Groups[].Value;
string month = match.Groups[].Value;
string day = match.Groups[].Value;
this.birthCode = year + month + day;
this.randomCode = match.Groups[].Value;
this.sexCode = char.Parse(match.Groups[].Value);
string verifyCode = match.Groups[].Value.ToUpper(); if (this.ValidateVerifyCode(this.Id.Substring(, ), char.Parse(verifyCode)))
{
try
{
this.Birth = BirthDate.GetBirthDate(year, month, day);
this.Area = AreaCodeMapping.GetArea(this.areaCode);
Sex = GetSex(this.sexCode);
}
catch (System.Exception ex)
{
return ex.Message;
}
return string.Empty;
}
}
return "身份证号码格式错误";
} /// <summary>
/// 验证验证码
/// </summary>
/// <param name="bodyCode">bodyCode</param>
/// <param name="verifyCode">verifyCode</param>
/// <returns>结果</returns>
private bool ValidateVerifyCode(string bodyCode, char verifyCode)
{
char calculatedVerifyCode = this.GetVerifyCode(bodyCode);
return calculatedVerifyCode == verifyCode;
} /// <summary>
/// 15位身份证
/// </summary>
/// <returns>结果</returns>
private string ParseCardInfo15()
{
const string CardIdParttern = @"(\d{6})(\d{2})(\d{2})(\d{2})(\d{2})(\d{1})";
Match match = Regex.Match(this.Id, CardIdParttern);
if (match.Success)
{
this.areaCode = match.Groups[].Value;
string year = match.Groups[].Value;
string month = match.Groups[].Value;
string day = match.Groups[].Value;
this.birthCode = year + month + day;
this.randomCode = match.Groups[].Value;
this.sexCode = char.Parse(match.Groups[].Value); try
{
this.Area = AreaCodeMapping.GetArea(this.areaCode);
this.Birth = BirthDate.GetBirthDate(year, month, day);
Sex = GetSex(this.sexCode);
}
catch (System.Exception ex)
{
return ex.Message;
}
return string.Empty;
}
return "身份证号码格式错误";
} /// <summary>
/// 获取验证码
/// </summary>
/// <param name="bodyCode">bodyCode</param>
/// <returns>结果</returns>
private char GetVerifyCode(string bodyCode)
{
char[] bodyCodeArray = bodyCode.ToCharArray();
////int sum = 0;
////for (int index = 0; index < bodyCodeArray.Length; index++)
////{
//// sum += int.Parse(bodyCodeArray[index].ToString()) * GetWeight(index);
////}
////return this.verifyCodeMapping[sum % 11];
int sum = bodyCodeArray.Select((t, index) => int.Parse(t.ToString()) * GetWeight(index)).Sum();
return this.verifyCodeMapping[sum % ];
} /// <summary>
/// GetWeight
/// </summary>
/// <param name="index">index</param>
/// <returns>index</returns>
private static int GetWeight(int index)
{
return ( << ( - index)) % ;
} /// <summary>
/// 获取性别
/// </summary>
/// <param name="sexCode">性别代码</param>
/// <returns>性别</returns>
private static Sex GetSex(char sexCode)
{
return ((int)sexCode) % == ? Sex.Female : Sex.Male;
}
} /// <summary>
/// 生日
/// </summary>
public struct BirthDate
{
/// <summary>
/// 年
/// </summary>
private readonly string year; /// <summary>
/// 月
/// </summary>
private readonly string month; /// <summary>
/// 日
/// </summary>
private readonly string day; /// <summary>
/// 默认
/// </summary>
public static BirthDate Empty
{
get { return new BirthDate("", "", ""); }
} /// <summary>
/// Initializes a new instance of the <see cref="BirthDate"/> struct.
/// </summary>
/// <param name="year">年</param>
/// <param name="month">月</param>
/// <param name="day">日</param>
public BirthDate(string year, string month, string day)
{
this.year = year;
this.month = month;
this.day = day;
} /// <summary>
/// 获取生日
/// </summary>
/// <param name="year">年</param>
/// <param name="month">月</param>
/// <param name="day">日</param>
/// <returns>结果</returns>
public static BirthDate GetBirthDate(string year, string month, string day)
{
DateTime date;
if (DateTime.TryParse(string.Format("{0}-{1}-{2}", year, month, day), out date))
{
return new BirthDate(year, month, day);
}
throw new System.Exception("日期不存在");
} /// <summary>
/// 年
/// </summary>
public string Year
{
get { return this.year; }
} /// <summary>
/// 年
/// </summary>
public string Month
{
get { return this.month; }
} /// <summary>
/// 日
/// </summary>
public string Day
{
get { return this.day; }
} /// <summary>
/// 重写ToString
/// </summary>
/// <returns>结果</returns>
public override string ToString()
{
return string.Format("{0}年{1}月{2}日", this.year, this.month, this.day);
} /// <summary>
/// 重写ToString
/// </summary>
/// <param name="separator">separator</param>
/// <returns>结果</returns>
public string ToString(string separator)
{
return string.Format("{1}{0}{2}{0}{3}", separator, this.year, this.month, this.day);
}
} /// <summary>
/// 性别
/// </summary>
public enum Sex
{
/// <summary>
/// 男
/// </summary>
Male, /// <summary>
/// 女
/// </summary>
Female
}
}

读取地区代码

 namespace Notify.Solution.Code.IdentityCard
{
/// <summary>
/// 区域配置
/// </summary>
public class AreaCodeMapping
{
/// <summary>
/// 区域字典
/// </summary>
private static readonly Dictionary<string, Area> areas; /// <summary>
/// Initializes static members of the <see cref="AreaCodeMapping"/> class.
/// </summary>
static AreaCodeMapping()
{
areas = LoadAreaInfo();
} /// <summary>
/// 加载信息
/// </summary>
/// <returns>区域信息</returns>
private static Dictionary<string, Area> LoadAreaInfo()
{
XmlDocument doc = LoadXmlDocument("AreaCodes.xml");
XmlNode areasNode = doc.SelectSingleNode("AreaCode");
if (areasNode != null)
{
XmlNodeList provinceNodeList = areasNode.ChildNodes;
return LoadProvinces(provinceNodeList);
} return null;
} /// <summary>
/// 加载XML
/// </summary>
/// <param name="fileName">文件名</param>
/// <returns>XmlDocument</returns>
private static XmlDocument LoadXmlDocument(string fileName)
{
var declaringType = MethodBase.GetCurrentMethod().DeclaringType;
if (declaringType != null)
{
string resourceName = declaringType.Namespace + "." + fileName;
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream(resourceName);
XmlDocument result = new XmlDocument();
if (stream != null)
{
result.Load(stream);
}
return result;
}
return null;
} /// <summary>
/// 解析XML节点
/// </summary>
/// <param name="provinceNodeList">provinceNodeList</param>
/// <returns>结果</returns>
private static Dictionary<string, Area> LoadProvinces(XmlNodeList provinceNodeList)
{
Dictionary<string, Area> result = new Dictionary<string, Area>();
foreach (XmlNode provinceNode in provinceNodeList)
{
string code = GetAttribute(provinceNode, "code");
string name = GetAttribute(provinceNode, "name");
Area province = new Area(code, name, null);
var cities = LoadCities(province, provinceNode.ChildNodes);
foreach (var city in cities)
{
province.AppendChild(city);
}
result.Add(code, province);
}
return result;
} /// <summary>
/// 加载城市
/// </summary>
/// <param name="province">省</param>
/// <param name="cityNodeList">节点</param>
/// <returns>结果</returns>
private static IEnumerable<Area> LoadCities(Area province, XmlNodeList cityNodeList)
{
List<Area> result = new List<Area>();
if (cityNodeList != null)
{
foreach (XmlNode cityNode in cityNodeList)
{
string code = GetAttribute(cityNode, "code");
string name = GetAttribute(cityNode, "name");
Area city = new Area(code, name, province);
var counties = loadCounties(city, cityNode.ChildNodes);
foreach (var county in counties)
{
city.AppendChild(county);
}
result.Add(city);
}
}
return result;
} /// <summary>
/// 加载区域
/// </summary>
/// <param name="city">市</param>
/// <param name="countyNodeList">节点</param>
/// <returns>结果</returns>
private static IEnumerable<Area> loadCounties(Area city, XmlNodeList countyNodeList)
{
List<Area> result = new List<Area>();
if (countyNodeList != null)
{
foreach (XmlNode countyNode in countyNodeList)
{
string code = GetAttribute(countyNode, "code");
string name = GetAttribute(countyNode, "name");
Area county = new Area(code, name, city);
result.Add(county);
}
}
return result;
} /// <summary>
/// 获取节点属性
/// </summary>
/// <param name="node">node</param>
/// <param name="attributeName">attributeName</param>
/// <returns>结果</returns>
private static string GetAttribute(XmlNode node, string attributeName)
{
if (node.Attributes != null)
{
XmlAttribute attribute = node.Attributes[attributeName];
return attribute == null ? string.Empty : attribute.Value;
}
return string.Empty;
} /// <summary>
/// 获取区域信息
/// </summary>
/// <param name="areaCode">区域代码</param>
/// <returns>结果</returns>
public static AreaInformation GetArea(string areaCode)
{
Area targetArea = null;
if (!string.IsNullOrWhiteSpace(areaCode) && areaCode.Length == )
{
string provinceCode = areaCode.Substring(, );
if (areas.ContainsKey(provinceCode))
{
var province = areas[provinceCode];
string cityCode = areaCode.Substring(, );
if (province.ContainsChild(cityCode))
{
var city = province.GetChild(cityCode);
string countyCode = areaCode.Substring();
if (city.ContainsChild(countyCode))
{
targetArea = city.GetChild(countyCode);
}
else
{
targetArea = city;
}
}
else if (province.ContainsChild(areaCode.Substring()))
{
targetArea = province.GetChild(areaCode.Substring());
}
else
{
targetArea = province;
}
}
}
return targetArea == null ? null : targetArea.ToAreaInformation();
}
} /// <summary>
/// 区域
/// </summary>
public class Area
{
/// <summary>
/// 子区域
/// </summary>
private readonly Dictionary<string, Area> childrenDic; /// <summary>
/// 区域集
/// </summary>
private readonly List<Area> childrenList; /// <summary>
/// Initializes a new instance of the <see cref="Area"/> class.
/// </summary>
/// <param name="code">代码</param>
/// <param name="name">名称</param>
/// <param name="parent">父区域</param>
internal Area(string code, string name, Area parent)
{
this.Info = new CodeNameMapping(code, name);
this.Parent = parent;
this.childrenDic = new Dictionary<string, Area>();
this.childrenList = new List<Area>();
} /// <summary>
/// 代码名称映射信息
/// </summary>
public CodeNameMapping Info
{
get;
private set;
} /// <summary>
/// 父区域
/// </summary>
public Area Parent
{
get;
private set;
} /// <summary>
/// 子区域
/// </summary>
public ReadOnlyCollection<Area> Children
{
get
{
return this.childrenList.AsReadOnly();
}
} /// <summary>
/// 区域集是否包含
/// </summary>
/// <param name="code">代码</param>
/// <returns>结果</returns>
internal bool ContainsChild(string code)
{
return this.childrenDic.ContainsKey(code);
} /// <summary>
/// 获取区域
/// </summary>
/// <param name="code">代码</param>
/// <returns>区域</returns>
internal Area GetChild(string code)
{
return this.childrenDic[code];
} /// <summary>
/// 父亲区域
/// </summary>
internal Area TopParent
{
get
{
return this.Parent == null ? this : this.Parent.TopParent;
}
} /// <summary>
/// 添加子区域
/// </summary>
/// <param name="child">子节点</param>
internal void AppendChild(Area child)
{
if (!this.childrenDic.ContainsKey(child.Info.Code))
{
this.childrenDic.Add(child.Info.Code, child);
this.childrenList.Add(child);
}
} /// <summary>
/// 区域信息转化
/// </summary>
/// <returns>区域信息</returns>
internal AreaInformation ToAreaInformation()
{
CodeNameMapping province = this.TopParent.Info;
CodeNameMapping city = default(CodeNameMapping);
CodeNameMapping county = default(CodeNameMapping);
if (this.Parent != null)
{
if (this.Parent.Info == province)
{
city = this.Info;
}
else
{
city = this.Parent.Info;
county = this.Info;
}
}
return new AreaInformation(province, city, county);
}
} /// <summary>
/// 区域信息
/// </summary>
public class AreaInformation
{
/// <summary>
/// Initializes a new instance of the <see cref="AreaInformation"/> class.
/// </summary>
/// <param name="province">省</param>
/// <param name="city">市</param>
/// <param name="county">区</param>
public AreaInformation(CodeNameMapping province, CodeNameMapping city, CodeNameMapping county)
{
this.Province = province;
this.City = city;
this.County = county;
} /// <summary>
/// 代码
/// </summary>
public string Code
{
get
{
return this.Province.Code + this.City.Code + this.County.Code;
}
} /// <summary>
/// 省
/// </summary>
public CodeNameMapping Province
{
get;
private set;
} /// <summary>
/// 市
/// </summary>
public CodeNameMapping City
{
get;
private set;
} /// <summary>
/// 区
/// </summary>
public CodeNameMapping County
{
get;
private set;
} /// <summary>
/// 名称
/// </summary>
public string FullName
{
get
{
return this.Province.Name + this.City.Name + this.County.Name;
}
} /// <summary>
/// 重写ToString
/// </summary>
/// <returns>结果</returns>
public override string ToString()
{
return this.FullName;
}
} /// <summary>
/// 代码名称映射
/// </summary>
public struct CodeNameMapping
{
/// <summary>
/// 代码
/// </summary>
private readonly string code; /// <summary>
/// 名称
/// </summary>
private readonly string name; /// <summary>
/// Initializes a new instance of the <see cref="CodeNameMapping"/> struct.
/// </summary>
/// <param name="code">代码</param>
/// <param name="name">名称</param>
internal CodeNameMapping(string code, string name)
{
this.code = code;
this.name = name;
} /// <summary>
/// 代码
/// </summary>
public string Code
{
get { return this.code; }
} /// <summary>
/// 名称
/// </summary>
public string Name
{
get { return this.name; }
} /// <summary>
/// 重写比较
/// </summary>
/// <param name="obj">对象</param>
/// <returns>结果</returns>
public override bool Equals(object obj)
{
if (obj != null && obj is CodeNameMapping)
{
return ((CodeNameMapping)obj).Code == this.Code;
}
return false;
} /// <summary>
/// GetHashCode
/// </summary>
/// <returns>HashCode</returns>
public override int GetHashCode()
{
return this.Code.GetHashCode();
} /// <summary>
/// 相等比较器
/// </summary>
/// <param name="left">left</param>
/// <param name="right">right</param>
/// <returns>结果</returns>
public static bool operator ==(CodeNameMapping left, CodeNameMapping right)
{
return left.Code != right.Code;
} /// <summary>
/// 不相等比较器
/// </summary>
/// <param name="left">left</param>
/// <param name="right">right</param>
/// <returns>结果</returns>
public static bool operator !=(CodeNameMapping left, CodeNameMapping right)
{
return left.Code != right.Code;
}
}
}

xml配置文件

下载地址

测试方法

         private static void Validator()
{
// 正确的
Validator v = new Validator("");
var rel = v.Execute(); // 错误的 更改第5位数
Validator v1 = new Validator("");
var rel1 = v1.Execute();
}

js验证点这里

.NET身份证验证的更多相关文章

  1. 身份证验证JS代码

    身份证验证JS程序function checkidcardfun(code) { var city = {11: "北京", 12: "天津", 13: &qu ...

  2. java身份证验证

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; impor ...

  3. jQuery身份证验证插件

    jQuery身份证验证插件 /*! * jQuery isIDCard Plugin v1.0.0 * http://www.cnblogs.com/cssfirefly/p/5629561.html ...

  4. java对身份证验证及正则表达式解析

    原文地址:http://www.cnblogs.com/zhongshengzhen/ java对身份证验证及正则表达式解析 package service; import java.text.Par ...

  5. Jsp注册页面身份证验证

    <!--身份证验证 --><script type="text/javascript">function isCardNo(Idcardnumber) { ...

  6. C#实现中国身份证验证问题

    C#中国身份证验证,包括省份验证和校验码验证,符合GB11643-1999标准...   今天写的 C#中国身份证验证,包括省份验证和校验码验证,符合GB11643-1999标准... 理论部分: 1 ...

  7. 【NumberValidators】大陆身份证验证

    需要说明的是这里的大陆身份证识别并不是公安局联网的识别,而是按国标GB 11643进行的验证,所以其验证结果只能说符合国标规范,但不能保证该身份证一定真实存在,如果你实际需求是希望身份证一定真实存在, ...

  8. Java正则表达式实现港、澳、台身份证验证

    最近由于业务的要求,需要进行港.澳.台人员身份证验证,现在直接上代码,经供参考学习,也为自己积累一些工具类: package com.qiu.validate; public class regexV ...

  9. js邮箱验证,身份证验证,正则表达式

    邮箱验证: html部分: 邮箱验证:<input type="text" id="mail" value="" / onkeyup= ...

  10. Java基础之身份证验证

    //简约版package test; import java.util.Scanner; public class ID { /** * 匹配算法 : 1) 得到17位身份证号码与下面给出的17位 2 ...

随机推荐

  1. 使用nvm管理node版本时,各个版本下公用npm安装的插件问题

    因为使用了NVM(node版本管理工具),所以在切换node版本的时候安装的插件不能共享使用,必须重新安装,导致不必要的工作量 所以我将npm(node包管理工具提取出来) 进行node版本之间的共享 ...

  2. .NET 互联网技术简介

    概述 技术更新太快,尤其是在互联网公司里,很多新的主流技术,我们还是必须要知道和熟练使用的.下面就给大家简单介绍,入门还是需要大家更努力的去深入学习. 目录 Git 入门 常用软件安装及VS插件工具 ...

  3. NC_Verilog中的工具ICC

    Cadence中的Incisive Comprehensive Coverage(ICC) solusion提供在仿真中的覆盖率分析. ICC中的覆盖率类型有两大类: 1)Code Coverage: ...

  4. matplotlib显示中文

    [注意] 可能与本文主题无关,不过我还是想指出来:使用matplotlib库时,下面两种导入方式是等价的(我指的是等效,当然这个说法可以商榷:) import matplotlib.pyplot as ...

  5. python3 列表的常用方法

    Python3中常用的列表方法(method) 见:help(list) 方法 意义 L.index(v [, begin[, end]]) 返回对应元素的索引下标, begin为开始索引,end为结 ...

  6. linux常用命令:df 命令

    linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 1.命令格式: df [选项] [文件] 2.命 ...

  7. python 四种方法修改类变量,实例对象调用类方法改变类属性的值,类对象调用类方法改变类属性的值,调用实例方法改变类属性的值,直接修改类属性的值

    三种方法修改类变量,实例对象调用类方法改变类属性的值,类对象调用类方法改变类属性的值,调用实例方法改变类属性的值,类名就是类对象,city就是类变量, #coding=utf-8 class empl ...

  8. nginx+tomcat把带WWW域名自动跳转到不带www域名方法

    nginx+tomcat把带WWW域名自动跳转到不带www域名方法在nginx.conf里面 include /etc/nginx/conf.d/*.conf;在应该server里增加: if ($h ...

  9. 利用canvas来绘制一个会动的图画

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. C/C++之类型强制转化

    强制转化四种类型可能很多人都常常忽略就象我一样,但是有时还是比较有用的.不了解的建议看看,一些机制我也不是十分了解,只是将一些用法写出来让大家看看.                           ...