• Python相关基础


    1》变量:

             

              

    2》条件判断与缩进:
      sex = raw_input("Please input your gender:")
      if sex == "girl":
        print ("I would like to have a little monker with jj!")
      elif sex == "man":
        print ("Going to homosexual!")
      else:
        print ("You are pervert!")
      =====================
      lunkey_number = 8
      number = input("Please input your guess number:")

      if number > lunkey_number:
        print ("Your guess number is too big,please input again:")
      elif number < lunkey_number:
        print ("Your guess number is too small,please input again:")
      else:
        print ("Your guess number is correct,you are lunkey!")

    3》循环控制

           

             优化代码:

              

               

    4》常用数据类型:
      数字:
        Int
        Float
        Long
      布尔:
        真或假
        1或0
      字符串:
         1>字符串的格式化:

                     

                  2>字符串常用功能:
          移除空白:可以去掉两边空格,也可去掉两边字符;

                        

                         

                           分割:
            长度:
            索引:
            切片:
            1>固定头部,不固定尾部,包含头部,不包含尾部;

                                   

                                   

                             2>指定分割的距离,不包含指定所用的索引

                                   

                         replace():转换特定字符;可以指定位置,将前几个替换;

                                 

                                 

                            splitlines():按照换行符来分割;

                                 

                                 

                               

                               swapcase():大小写转换; 

                                  

                                   

                  列表:可以存多个信息
          append:追加
              eg:name_list.append("haha")
          count:计算,统计;计算其中某个元素有几个
             eg:name_list.count("haha")
          extend:扩展 

                          

                           index:索引,输出最近的一个,如果有相同的
                eg:name_list.index("che")
           insert:插入,在某个位置插入一个元素
              eg:name_list.insert(2,"hhehe")
           pop:删除一个,每次都删除最后一个;
               eg:name_list.pop()
          remove:删除指定的一个
               eg:name_list.remove("zhang")
          reverse:反转,元素排序相反;

                                    

                        sort:排序,安装ASSCI码排序,数字排在最前面;
            eg:a.sort()
              extend():扩展列表;    

                                        

                                       

                    元组:
          tuple():可以将列表转换为元组;
          count():查看某元素出现的次数;

                           

                    字典 :
             fromkeys():生成一个新字典;

                             

                          get():当key不存在时可以输出一个默认值;

                                 

                                

                             keys(),values(),items():

                                 

                                 

                                

                          pop():删除某个键对,需要制定key值;

                                 

                                 

                                    update():更新字典;

                                       

        

  • 相关阅读:
    Azure PowerShell (7) 使用CSV文件批量设置Virtual Machine Endpoint
    Windows Azure Cloud Service (39) 如何将现有Web应用迁移到Azure PaaS平台
    Azure China (7) 使用WebMetrix将Web Site发布至Azure China
    Microsoft Azure News(4) Azure新D系列虚拟机上线
    Windows Azure Cloud Service (38) 微软IaaS与PaaS比较
    Windows Azure Cloud Service (37) 浅谈Cloud Service
    Azure PowerShell (6) 设置单个Virtual Machine Endpoint
    Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    功能代码(1)---通过Jquery来处理复选框
    案例1.用Ajax实现用户名的校验
  • 原文地址:https://www.cnblogs.com/xiaocheche/p/7624227.html
Copyright © 2020-2023  润新知