Python3 基础语法 从入门到精通二

来源:互联网 发布:安装windows 2003灰色 编辑:程序博客网 时间:2024/06/03 18:20
#Python3  变量赋值i = 100; #整型变量d = 100.0; #浮点型s = "Python3"; #字符串print(i);print(d);print(s);#Python3 列表list = ['one','two','three','four','five'];print(list);print(list[0]);print(list[1:3]);print(list[2:]);print(list * 2);#Python3 元组arraylist = ('1','2','3','4','5');print(arraylist);print(arraylist[0]);print(arraylist[1:3]);print(arraylist[2:]);print(arraylist * 2);# Python3 字典dirt ={};dirt['one'] = 'one';dirt['two'] = 'two';dirt['thress'] = 'three';dirt['four'] = 'four';dirt['five'] = 'five';dirt[0] =0;dirt[1] =1;dirt[2] =2;dirt[3] =3;print(dirt['one']);print(dirt[0]);print(dirt);print(dirt.keys());print(dirt.values());#Python3 数据类型转换a = int('1');print("type is {0}".format(type(a))); #type 基础数据类型判断b = float(1);print("type is {0}".format(type(b))); #type 基础数据类型判断c = str(1);print("type is {0}".format(type(c))); #type 基础数据类型判断d = repr(1.0);print("type is {0}".format(type(d))); #type 基础数据类型判断#Python3 成员运算符e = 1;f = 6;lists = [1,2,3,4,5];def whether(a,b):    if(a in b):        return 'true';    else:        return 'false';print("e is it inside {0}".format(whether(e,lists)));print("f is it inside {0}".format(whether(f,lists)));#Python3 身份运算符(基于对象)class Dog:    def __init__(self,weight):        self.weight = weight;    def getWeight(self):        print("my weight is {0}".format(self.weight));toady = Dog(10);boogie = Dog(15);if(toady is boogie):    print("true");else:    print("false");#Python3 身份运算符(基于数据类型)a = 10;b = 10;if(a is b):    print("true");else:    print("false");

0 0
原创粉丝点击