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

1.字符串取值实例:

samp_string = "Whatever you are, be a good one."

for i in samp_string:
print(i)
for i in range(,len(samp_string)-,):
print(samp_string[i]+samp_string[i+]) print('A=',ord("A"))
print('65=',chr()) print('桃:',ord("桃"))
print('',chr()) # # You can get a character by referencing an index
# print(samp_string[]) print(samp_string[])
# # Get the last character
print(samp_string[-])
#
# # Get the string length
print("Length : ", len(samp_string))
#
# # Get a slice by saying where to start and end
# # The 4th index isn't returned
print(samp_string[:])
#
# # Get everything starting at an index
print(samp_string[:])
# print()
#
print(samp_string)
print(samp_string[::])
print(samp_string[::])
#
# # Reverse the string
print(samp_string[::-])
# # Palindrome
print('I did, did I?'[::-])
print('No lemon, no melon'[::-])
#
# # Practical use
url = "http://pythonabc.org"
# Get the top level domain
print(url[-:])
# Print the url without the http://
print(url[:])
# Print the url without the http:// or the top level domain
print(url[:-])

2,列表取值取值实例

my_list=[, , , , , , , , , ]
# , , , , , , , , ,
# -,-,-,-,-,-,-,-,-,- # 取其中一个值
print(my_list[])
print(my_list[-])
print(my_list[-]) # 取其中几个值
print(my_list[:])
print(my_list[-:-])
print(my_list[-:-:]) # 逆序输出
print(my_list[::-])
print(my_list[-:-:-]) # 注意逆序输出,开始点在结束点的后面
print(my_list[-:-:-]) # 注意逆序输出,开始点在结束点的后面 strList=["string",,21.0]
# 列表基本操作
print("列表长度:",len(strList))
print("列表输出",strList)
print("两个列表相加为一个列表:",my_list+strList) # 判断一个元素是否为列表中的元素
print("string" in strList)
# ************列表相关方法*************************
# 找出特定元素的索引,字符串使用find方法找到,列表用index方法找到
print(strList.index())
for element in strList:
print("{}:{}".format(strList.index(element),element))
# 特定元素的的个数 字符串和数组都是使用count方法计算特定子字符串和元素的个数
print("string 的个数:",strList.count('string')) # 添加元素
strList.append("final")
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. How do negative margins in CSS work and why is (margin-top:-5 != margin-bottom:5)?

    How do negative margins in CSS work and why is (margin-top:-5 != margin-bottom:5)? 解答   Negative mar ...

  2. Swift 自动引用计数(ARC)

    Swift 使用自动引用计数(ARC)这一机制来跟踪和管理应用程序的内存 通常情况下我们不需要去手动释放内存,因为 ARC 会在类的实例不再被使用时,自动释放其占用的内存. 但在有些时候我们还是需要在 ...

  3. eclipse 创建web项目,新建servelet实例

    参考: http://www.phperz.com/article/14/1127/38108.html http://jingyan.baidu.com/article/c843ea0b9aa914 ...

  4. C语言包含头文件时用引号和尖括号的区别

    用尖括号 #include <>:    一般用于包含标准的库头文件,编译器会去系统配置的库环境变量和者用户配置的路径去搜索,而不会在项目的当前目录去查找 用双引号 #include &q ...

  5. [转]Maven项目读取src.main.resources下的文件

    要取编译后的路径,而不是你看到的src/main/resources的路径.如下: URL url = MyTest.class.getClassLoader().getResource(" ...

  6. ubuntu16.04 下通过rc.d(rc.local)实现开机启动(未登录)anydesk

    先编辑anydesk-X.X.X/init/anydesk文件,将"DAEMON=//usr/bin$NAME"改成"DAEMON=/XXX/anydesk-5.1.1/ ...

  7. Leetcode 69. Sqrt(x)及其扩展(有/无精度、二分法、牛顿法)详解

    Leetcode 69. Sqrt(x) Easy https://leetcode.com/problems/sqrtx/ Implement int sqrt(int x). Compute an ...

  8. sizeof与strcpy的区别

    转自:http://c.biancheng.net/view/342.html 表面上看strcpy和sizeof都是求字符串的长度,但是二者却存在着许多不同之处及本质区别 strlen是一个函数,用 ...

  9. ip routing 开启三层路由模式

    no ip router是关闭路由协议,no ip routing 是关闭三层的路由工作模式 no ip route是删除某条(静态)路由,比如no ip router 0.0.0.0 0.0.0.0 ...

  10. tensorflow搭建神经网络

    最简单的神经网络 import tensorflow as tf import numpy as np import matplotlib.pyplot as plt date = np.linspa ...