zoukankan      html  css  js  c++  java
  • python 基础

    Python 中的变量赋值不需要类型声明。

    print("---------------------------------数字---------------------------------")

    num1 = 1;

    print("---------------------------------字符串---------------------------------")

    str1 = "str";


    print
    ("---------------------------------列表---------------------------------") print(" 切割可以用 [头下标:尾下标] ") 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(" 元组用 () 标识。内部元素用逗号隔开。但是元组不能二次赋值,相当于只读列表。") 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')

       python 中 ==和is的区别

  • 相关阅读:
    hdu 1312 Red and Black
    hdu 1573 X问题
    广工校赛决赛之简单的数论题
    最大的LeftMax与rightMax之差绝对值
    POJ 2385 Apple Catching
    hdu 1171 Big Event in HDU
    ACM比赛经验
    BestCoder Valentine's Day Round
    使用ffmpeg进行视频封面截取
    使用ODP.NET连接Oracle数据库
  • 原文地址:https://www.cnblogs.com/mafy/p/11887555.html
Copyright © 2011-2022 走看看