Python学习第一天 -- 简单的属性、 语法学习

1,哈哈哈,是时候来一波Python,其实没办法,最近在做后台的时候,需要用到Python来调试接口,下面是它的简单的语法,权当是记录。

2,

#!/user/bin/python
# coding=utf-8
# print "Hello World" ;
"""
1,这里是多行注释,可以使用三个双引号或者三个单引号
"""

"""
2, Python 3.0版本已将将print作为一个内置函数,所以可以这样写一下的语句,特别提醒,当文件中存在中文的时候,我们要加上coding=utf-8
print ("Hello World");

#控制用户输入语句
raw_input("

Press the enter key to exit.");
"""

# #一行显示多个语句
# import sys ;
# x = 'wangjitao';
# sys.stdout.write(x+'
');

"""
3,变量类型:常见的有整形、浮点、字符串类型
但是标准的数据类型包含下面五个:
    ① Number(数字) 常见的数字包含 int,long,float,complex(复数)
    ② String (字符串)
    ③ List (列表)
    ④ Tuple (元组)
    ⑤ Dictionary (字典)
    ⑥ Sets (集合)

# count = 100;
# miles = 1000.0;
# name = "wangjtiao";
#
# print count;
# print miles;
# print name;

"""
"""
4,String 类型中 *表示重复操作 +表示链接字符串

str = "wangjtiao";
print str;
print str[0];
print str[2:5];
print str[2:];
print str*2;
print str+"ceshi ";
"""

"""
5,列表 *表示重复操作 +表示连接

list = ["wangjitao",234,2.34,'john'];
tinylist = [123,"gaowenhan"];

print list;
print list[0];
print list[1:3];
print list[1:]
print tinylist*2;
print list+tinylist;

"""
"""
6,元组,是另一种数据类型,类似于List,元组用“()”标识,内部元素使用逗号隔开,但元组不能二次赋值,只读列表

tuple = ("wangjitao",111,12.3,"gaoweee");
print tuple;
print tuple[0];

tuple[2] = 100; 这句话报错,不允许被二次赋值

"""

"""
7,Set(集合) 无序不重复的序列,基本关系是进行成员关系测试和删除的序列
可以使用大括号({})或者set()函数创建集合


student = {'Tom', 'Jim', 'Mary', 'Tom', 'Jake'}
print student;  # 重复的元素会自动会去掉

# 成员测试
if ('Rose' in student):
    print ("Rose is not in student")
else:
    print ("Rose is not in student")

# set可以进行集合运算
a = set('abcddsfdsf');
b = set("alasdd");

print a;
print(a - b);  # 差
print (a | b);  # 并

"""

"""
8,字典(dictionary)是Python中另一个非常有用的内置数据类型。
列表是有序的对象结合,字典是无序的对象集合。两者之间的区别在于:字典当中的元素是通过键来存取的,而不是通过偏移存取。
字典是一种映射类型,字典用"{ }"标识,它是一个无序的键(key) : 值(value)对集合。
键(key)必须使用不可变类型。
在同一个字典中,键(key)必须是唯一的。
dict = {}
dict['one'] = "1 - 菜鸟教程"
dict[2]     = "2 - 菜鸟工具"

tinydict = {'name': 'runoob','code':1, 'site': 'www.runoob.com'}

print (dict['one'])       # 输出键为 'one' 的值
print (dict[2])           # 输出键为 2 的值
print (tinydict)          # 输出完整的字典
print (tinydict.keys())   # 输出所有键
print (tinydict.values()) # 输出所有值
"""

flag = False ;
if flag :
    print ("flag is true");
else:
    print ("flag is flase");

  

原文地址:https://www.cnblogs.com/wjtaigwh/p/6178495.html