python 基础
Python 中的变量赋值不需要类型声明。
print("---------------------------------数字---------------------------------")
num1 = 1;
print("---------------------------------字符串---------------------------------")
str1 = "str";
print("---------------------------------列表---------------------------------") print("\n 切割可以用 [头下标:尾下标] ") list1 = [1,2,3,4,5,6,7,8,9] list1[1] = 3 print(list1) print(list1[:]) print(list1[3:]) print(list1[:5]) print(list1[1:9]) print(list1[1:-5]) print("---------------------------------元组---------------------------------") print("\n 元组用 () 标识。内部元素用逗号隔开。但是元组不能二次赋值,相当于只读列表。") tuple1 = ("a",2,"b",4,"c") print(tuple1) print("其他截取通list") print("---------------------------------字典-----------map----------------------") dict1 = {} dict1['one'] = "This is one" dict1[2] = "This is two" tinyDict = {'name': 'john','code':6734, 'dept': 'sales'} print(dict1['one']) print(dict1[2]) print(dict1.keys()) print(dict1.values())
for循环: def testFor(self): fruits = ['banana', 'apple', 'mango'] for i in fruits: print(i) while: def testWhile(self): fruits = ['banana', 'apple', 'mango'] __ind = len(fruits) print("len",__ind) __i = 0; while(__i < __ind): print(fruits[__i]) __i += 1
静态方法:用 @staticmethod修饰 @staticmethod def staticMethod(): print('staticMethod')