管窥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 ...
随机推荐
- java源码
Java泛型中的标记符含义: K - Key(键) V - Value(值) E - Element (在集合中使用,因为集合中存放的是元素) T - Type(Java 类,可做泛型) N - Nu ...
- C#使用OracleDataReader返回DataTable
string data = string.Empty; DataTable OutDataTable = new DataTable(); OracleDataReader daReader = cm ...
- 洛谷 P1068 分数线划定【排序+模拟】
世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,AA市对 所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试.面试分数线根 据计划录取人数的150\%150%划 ...
- 47.serch基本语法
主要知识点 1._search api基本语法 2.http协议中get请求带上request body 一.search api的基本语法 1.GET /_search {所传递的参 ...
- 使用VS Code断点调试PHP
vs code 使用一款杰出的轻量级代码编辑器,其中的插件工具不胜枚举而且还在不断增加.使用 vs code 调试 php 代码更是方便简洁,下面我们来一起看一下. 1. 安装 XDebug 扩展 调 ...
- CSS3 timing-function: steps()介绍
在应用 CSS3 渐变/动画时.有个控制时间的属性 <timing-function>.它的取值中除了经常使用到的三次贝塞尔曲线以外,还有个steps() 函数. steps 函数指定了一 ...
- python使用pytest+pytest报告
需要安装pytest和pytest-html pip3 install -U pytest pip3 install -U pytest-html
- UVA - 11077 Find the Permutations (置换)
Sorting is one of the most usedoperations in real life, where Computer Science comes into act. It is ...
- iOS 块的简单理解
占位 自己主动转载器那小子,你转完了没? 转完了,我开写了哈! Block,就两个事儿,一个是引用,一个是实例,除了实现处.其他地方都是引用. 以此思路.再继续看看引用和实现的定义方式吧. 參考官方文 ...
- Linux用户和组的管理
一.概述: 1.Linux下的三类用户: (1).超级用户(root)具有操作系统的一切权限UID值均为0 (2).普通用户具有操作系统有限的权限UID值500~6000 (3).伪用户是为了方便系统 ...