管窥python语法
刚接触python,mark下所见所得:
1.Python调用底层API,可在任何platform上运行,包括Windows、Mac、Unix;
2.用#符号对代码或语句进行注释,#后的代码不被编译;
3.print的时候使用逗号[,]告诉解释器不作新行输出;
4.python程序可以运行在windows shell里(cmd line);
5.代码可以在notepad下编辑,纯文本结构文件;
6.变量声明:v=2; v="can be changed to a string"; #the value of v can be changed at any time;
name="paul cheng";同样用加号进行字符串连接;
7.while循环:[代码逻辑结构完全用缩进控制,新鲜清洁]
n=1
while n<10:
print n
n=n+1
8.function:
1)definition:
def hello():
print "hello"
return 1234
2)invoke:
"print hello()" will output result like: [after execution of print "hello", function returns 1234 for printing]
hello
1234
9.Tuples, Lists, Dictionaries.
1)Tuples: month = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun')
2)Lists: cats = ['Tom', 'Snappy', 'Kitty', 'Jessie', 'Chester']
add: cats.append("appendOne")
delete: cats.remove("Tom") or del cats[n];
get one: cats[1] will get "Snappy";
get many: cats[0:2] will get "'Tom','Snappy','Kitty'";
3)Dictinonaries: phonebook = {'paul cheung':123456, 'chirs paul':654321}
add: phonebook['key']=value
delete: del phonebook['key']
keys: phonebook.keys() will return all keys as a list;
values: phonebook.values() will return all values as a list;
10.loop-for:
for item in list:
print item
11.class:
class person: #definition
def _init_(selef, name, age): #.ctor
self.name=name
self.age=age
class student(person): #inheritence
{statement...}
12.module: #include variables/function/class;
13.import module:
import module_name
from module_name import function_name/class_name
14.use imported module:
module_name.function_name/class;
function_name if use from...import...
15.file I/O:
file = open('file_name', 'r/w')
file.seek(int, int) #moving cursor
16.error handling:
try:
{statement...}
except NameError:
{...} #handle a type of error
except SyntaxError:
{...} #handle another type of error
or except (NameError, SyntaxError)
{...} #handle multilple types of error together
管窥python语法的更多相关文章
- 对 Python 语法不够了解导致的 bug
对 Python 语法不够了解导致的 bug. `in` '20' in '11264,6144,4096,3072,2048,1024,300,30' Out[7]: True a_list = ' ...
- python 笔记2:python语法基础
python语法学习笔记: 1 输入输出 input(),print(). name = input('input your name : ')print('hello ,'+name)print(& ...
- python语法快速入门(1)
http://www.runoob.com/python/python-tutorial.html Python 是一种解释型语言: 这意味着开发过程中没有了编译这个环节.类似于PHP和Perl语言 ...
- python语法笔记(四)
1.对象的属性 python一切皆对象,每个对象都可能有多个属性.python的属性有一套统一的管理方案. 属性的__dict__系统 对象的属性可能来自于其类定义,叫做类属性:还可能 ...
- python语法-[with来自动释放对象]
python语法-[with来自动释放对象] http://www.cnblogs.com/itech/archive/2011/01/13/1934779.html 一 with python中的w ...
- wxpython 支持python语法高亮的自定义文本框控件的代码
在研发闲暇时间,把开发过程中比较重要的一些代码做个珍藏,下面的代码内容是关于wxpython 支持python语法高亮的自定义文本框控件的代码,应该是对大家也有用. import keywordimp ...
- Python语法的转义字符
Python语法的转义字符 转义字符 说 明 \ 续行符 \n 换行符 \0 空 \t 水平制表符,用于横向跳到下一制表位 \'' 双引号 \' 单引号 \\ 一个反斜杠 \f 换页 \0dd 八进 ...
- Python语法教程总结规范
Python语法易错点记录 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享. ...
- 初试Python语法小试牛刀之冒泡排序
Python很火,心里很慌,没吃过猪肉,也要见见猪走路. 看了几天Python的语法,大概初步了解了一点点,https://www.liaoxuefeng.com/wiki/0014316089557 ...
随机推荐
- 整理Webview加载缓慢的解决方案
1.https://www.cnblogs.com/xinye/p/3144139.html 2.https://www.jianshu.com/p/95d4d73be3d1
- 有关微信小程序
每个页面都要在app.json中配置 "pages": [ "pages/index/index", "pages/list/list", ...
- eas之f7
f7控件实际上是一张单据.所以对于数据的修改实际上是需要修改单据的,是在eas中修改单据的元数据是组件.包括了f7控件, F7是个快捷键,是某个字段符合条件的集合! F7就是一个控件,用来 ...
- for 循环的反汇编浅析
for 循环 for 循环是使用频度最高的循环结构,我们通过 C 语言反汇编实例,来分析 for 循环结构在计算机底层的原理和构造.首先,我们编写一个简单的 for 循环: 为了方便观察,我们用十六进 ...
- js数组对象去重
转: https://www.cnblogs.com/gaoht/p/9850449.html 在数组对象中去掉重复的对象: export function deteleObject(obj) { v ...
- 22.external version
主要知识点 基于external version进行乐观锁并发控制 es提供了一个feature,就是说,你可以不用它提供的内部_version版本号来进行并发控制,可以基于你自己维护的一个版本号来进 ...
- Python 实现 Excel 里单元格的读写与清空操作
#coding=utf-8 # coding=utf-8 作用是声明python代码的文本格式是utf-8,python按照utf-8的方式来读取程序. # 如果不加这个声明,无论代码中还是注释中有中 ...
- RedisTemplate Api总结
RedisTemplate 使用总结 最近在做一个项目,考虑到有累计,排行,缓存等功能:而Redis是一个基于内存的数据库,而且提供了 字符串(String), 哈希(Map), 列表(list), ...
- myquant平台搭建及使用
1.主页 http://myquant.cn/ 点击“我要申请试用”,进入如下页面:http://myquant.cn/news/2015/03/25/try-gmsdk-v2.0/ 点击“试用注册” ...
- xtrabackup增量备份mysql +MHA
http://blog.csdn.net/yanggd1987/article/category/2214421 https://www.centos.bz/2013/09/innobackupex- ...