Python 字符串——巧取值和列表——巧取值 对比

1.字符串取值实例:

  1. samp_string = "Whatever you are, be a good one."
  2.  
  3. for i in samp_string:
  4. print(i)
  5. for i in range(,len(samp_string)-,):
  6. print(samp_string[i]+samp_string[i+])
  7.  
  8. print('A=',ord("A"))
  9. print('65=',chr())
  10.  
  11. print('桃:',ord("桃"))
  12. print('',chr())
  13.  
  14. # # You can get a character by referencing an index
  15. # print(samp_string[])
  16.  
  17. print(samp_string[])
  18. # # Get the last character
  19. print(samp_string[-])
  20. #
  21. # # Get the string length
  22. print("Length : ", len(samp_string))
  23. #
  24. # # Get a slice by saying where to start and end
  25. # # The 4th index isn't returned
  26. print(samp_string[:])
  27. #
  28. # # Get everything starting at an index
  29. print(samp_string[:])
  30. # print()
  31. #
  32. print(samp_string)
  33. print(samp_string[::])
  34. print(samp_string[::])
  35. #
  36. # # Reverse the string
  37. print(samp_string[::-])
  38. # # Palindrome
  39. print('I did, did I?'[::-])
  40. print('No lemon, no melon'[::-])
  41. #
  42. # # Practical use
  43. url = "http://pythonabc.org"
  44. # Get the top level domain
  45. print(url[-:])
  46. # Print the url without the http://
  47. print(url[:])
  48. # Print the url without the http:// or the top level domain
  49. print(url[:-])

2,列表取值取值实例

  1. my_list=[, , , , , , , , , ]
  2. # , , , , , , , , ,
  3. # -,-,-,-,-,-,-,-,-,-
  4.  
  5. # 取其中一个值
  6. print(my_list[])
  7. print(my_list[-])
  8. print(my_list[-])
  9.  
  10. # 取其中几个值
  11. print(my_list[:])
  12. print(my_list[-:-])
  13. print(my_list[-:-:])
  14.  
  15. # 逆序输出
  16. print(my_list[::-])
  17. print(my_list[-:-:-]) # 注意逆序输出,开始点在结束点的后面
  18. print(my_list[-:-:-]) # 注意逆序输出,开始点在结束点的后面
  19.  
  20. strList=["string",,21.0]
  21. # 列表基本操作
  22. print("列表长度:",len(strList))
  23. print("列表输出",strList)
  24. print("两个列表相加为一个列表:",my_list+strList)
  25.  
  26. # 判断一个元素是否为列表中的元素
  27. print("string" in strList)
  28. # ************列表相关方法*************************
  29. # 找出特定元素的索引,字符串使用find方法找到,列表用index方法找到
  30. print(strList.index())
  31. for element in strList:
  32. print("{}:{}".format(strList.index(element),element))
  33. # 特定元素的的个数 字符串和数组都是使用count方法计算特定子字符串和元素的个数
  34. print("string 的个数:",strList.count('string'))
  35.  
  36. # 添加元素
  37. strList.append("final")
  38. print("string 的更新后个数:",len(strList))

Python 字符串——巧取值和列表——巧取值 对比的更多相关文章

  1. Python 字符串,元祖,列表之间的转换

    1.字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'Hello World!' 2. ...

  2. Python直接改变实例化对象的列表属性的值 导致在flask中接口多次请求报错

    错误原理实例如下: class One(): list = [1, 2, 3] @classmethod def get_copy_list(cls): # copy一份list,这样对list的改变 ...

  3. python 字符串(str)和列表(list)的互相转换

    1.str to list  str1 = "12345"list1 = list(str1)print list1 str2 = "123 sjhid dhi" ...

  4. nodejs抓取数据一(列表抓取)

    纯属初学...有很多需要改进的地方,请多多指点... 目标是抓取58同城 这个大分类下的列表数据: http://cd.58.com/caishui/?PGTID=14397169455980.924 ...

  5. Python开发(二):列表、字典、元组与文件处理

    Python开发(二):列表.字典.元组与文件处理 一:列表二:元组三:字典四:文件处理 一:列表   为什么需要列表 可以通过列表可以对数据实现最方便的存储.修改等操作.字符串是不能修改的,所以无法 ...

  6. python字符串、列表通过值找索引/键

    python透过"值"找字符串和列表中的索引和键. 1 #!usr/bin/env python3 2 #-*- coding=utf-8 -*- 3 4 ''' 5 python ...

  7. python字符串、列表、字典的常用方法

    一.python字符串的处理方法 >>> str = ' linzhong LongXIA ' >>> str.upper() #字符串str全部大写 ' LINZ ...

  8. 初识python 字符串 列表 字典相关操作

    python基础(一): 运算符: 算术运算: 除了基本的+ - * / 以外,还需要知道 :  // 为取整除 返回的市商的整数部分 例如: 9 // 2  ---> 4  , 9.0 //  ...

  9. python 字符串方法及列表,元组,字典(一)

    字符串 str 注: 若想要保持单引号和双引号为字符串的一部分 1)单双引号交替使用, 2)使用转义字符\ 3)成对三个引号被存在变量里 二.字符串详细用法 字符串的单个取值例 p_1=”hello” ...

随机推荐

  1. 使用log4j使某些java类的日志信息输出到指定日志文件中

    Log4j 是 Apache 的一个开放源代码项目,通过使用 Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI 组件.甚至是套接口服务器.NT 的事件记录器.UNIX Syslog ...

  2. 通过Vagrant搭建PHP环境(一) Vagrant box添加配置

    系统Windows10 Vagrant 1.8.1 VirtualBox 5.0.20 vagrant box下载地址:http://cloud.centos.org/centos/7/vagrant ...

  3. 网络时间协议 (SNTP)

    sntp是简单网络时间协议(Simple Network Protocol)的客户端,可以用来查询或修正NTP服务器的时间和本地的时差. sntp可以以非交互模式运行或运行一个计划任务的脚本. snt ...

  4. [Oracle] 简单建表语句

    // 注意表名,字段名,索引名 尽量不要带引号 CREATE TABLE FIRSTTB    ( "ID" NUMBER(8,0) not null primary key, & ...

  5. C之输入输出

    %d - int%ld – long (long int)%lld - long long%hd – short 短整型 (half int) %c - char%f - float%lf – dou ...

  6. python中的tcp示例详解

    python中的tcp示例详解  目录 TCP简介 TCP介绍 TCP特点 TCP与UDP的不同点 udp通信模型 tcp客户端 tcp服务器 tcp注意点   TCP简介   TCP介绍 TCP协议 ...

  7. 常见的RSA套路脚本

    工具 rsatool https://github.com/ius/rsatool factordb(分解大素数) http://www.factordb.com python-PyCrypto库 O ...

  8. win7上 nginx 出现 403 Forbidden

    一般是目录权限问题,在conf文件找到 location / { index index.html index.htm index.php;# autoindex on; } 把#去掉就可以了.

  9. 微信小程序 — 自定义picker选择器弹窗内容+textarea穿透bug

    微信小程序中定义好的几种picker选择器,不管是日期选择器还是地区选择器,或是其他的都只有定死的样式和内容. 但是大多数开发程序的情况下还是需要自己写样式的,或是内容的. 例如: 代码如下: < ...

  10. VAO和VBO

    我想大家都已经熟悉VBO了吧.在GL3.0时代的VBO大体还是处于最重要的地位,但是与此同时也出现了不少新的用法和辅助役,其中一个就是VAO.本文大致小记一下这两者的联系,帮助大家理解一下这个角色.— ...