py_One
1.Python 标识符
在 Python 里,标识符由字母、数字、下划线组成。 在 Python 中,所有标识符可以包括英文、数字以及下划线(_),但不能以数字开头。 Python 中的标识符是区分大小写的。 以下划线开头的标识符是有特殊意义的。以单下划线开头 _foo 的代表不能直接访问的类属性,需通过类提供的接口进行访问,不能用 from xxx import * 而导入。 以双下划线开头的 __foo 代表类的私有成员,以双下划线开头和结尾的 __foo__ 代表 Python 里特殊方法专用的标识,如 __init__() 代表类的构造函数。 Python 可以同一行显示多条语句,方法是用分号 ; 分开,如: >>> print 'hello';print 'runoob';
hello
runoob
2.python变量类型
int(有符号整型) long(长整型[也可以代表八进制和十六进制]) float(浮点型) complex(复数)
数字变量
name = 'python'
id = '' # 字符串或串(String)是由数字、字母、下划线组成的一串字符。
字符串变量
# 定义 注意列表元素可重复
city = ['Guangzhou', 'Shanghai','Beijing', 'Beijing', 'Tianjin'] # 列表检索
city_1 = city[1] # 根据元素序号检索列表中元素 city_end = city[-1] # 可用来检索列表最后的元素
列表
# 只读,不能修改。用 () 标识
name = ('python', 'java', 'C', 'C#') print(name[0]) print(name[0:2]) # 输出 ('python', 'java')
元组
dic = {
'name':'XXX',
'id' :"",
1 :'ddd'
} print(dic[1])
print(dic['name'])
字典
3.运算符号
基本运算符有 + ,-, *,/,%(取模),**(幂),//(取整除向,下取整)
=(赋值),==(判等),!=(不等于),<>(不等于),>(大于),<(小于),>=(大于等于),<=(小于等于)
4.条件语句
a = 5; b = 6; c = 0
if a > c:
print("a>c")
else:
print("a<c") # 多个条件
if a>c:
print("a>c")
elif a == c:
print("a=c")
else:
print("a<c")
if语句
5.循环语句
for num in range(0, 10):
print(num)
>>0,1,2,3,4,5,6,7,8,9 for ss in "Apple":
print(ss)
>>A,p,p,l,e fruits = ["Apple", "banana", "mango"]
for fruit in fruits:
print(fruit) # 通过下标检索循环
for ff in range(len(fruits)):
print(fruits[ff])
>>Apple,banana,mango
for循环
# while循环
num = 0
while num < 5:
print num
num += 1
>>0,1,2,3,4 # 无限循环
while True:
print("循环中。。。")
# break
while循环
py_One的更多相关文章
随机推荐
- 洛谷T47092 作业_简单状压动归
只要注意一下细节就毫无难点了,简简单单状态压缩即可. Code: #include<cstdio> #include<algorithm> using namespace st ...
- GitHub报错error: bad signature
Git报错 bad signature 将文件提交到仓库时,抛出以下错误: 报错 Roc@DESKTOP-AF552U2 MINGW64 /e/note/Git (master) $ git add ...
- js获取路径参数对象
/** * 获取页面路径参数值 */ function getParams(key) { var result = {}; var paramStr = encodeURI(window.docume ...
- 使用命令:ssh-add 时,出现 “Could not open a connection to your authentication agent.”
为 GitHub 账号设置 SSH Key时, 使用命令:ssh-add,出现“Could not open a connection to your authentication agent”,解决 ...
- 支持Openflow 1.3的wireshark插件安装教程
目前为止,我们使用openflow wiki里提供的minient镜像里集成的wireshark只支持openflow1.0,我们通过wireshark上 菜单 help-->about wir ...
- 前后端交互&交互接口
前后端数据交互之数据接口 废话就不多说了,我们都知道,前端通常会通过后台提供的接口来获取数据来完成前端页面的渲染. 1.前端通过接口调用后台返回的数据 <!DOCTYPE html PUBLIC ...
- HTML5常见的面试题,基础知识点
HTML5常见的面试题 一.HTML 常 ...
- HAVING使用子查询
HAVING使用子查询 //查询各部门平均工资,显示平均工资大于 //公司整体平均工资的记录 select deptno,avg(sal) from emp group by ...
- QQ在线人数统计图数据解析
转载请注明出处:http://blog.csdn.net/xiaoy_h/article/details/27980851 我相信非常多人一定去过这个地方: http://im.qq.com/onli ...
- 强名称程序集(strong name assembly)——为程序集赋予强名称
,唯一标识一个程序集 2,放置程序集被仿冒和被篡改. 3,能够部署到全局程序集缓存(GAC:GlobalAssembly Cache)中:在将强名称程序集不熟在GAC其中以后,强名称程序集也能够称为共 ...