shoplist = ['apple', 'mango', 'carrot', 'banana']

print('I have ', len(shoplist), ' items to purchase.')
print('These items are: ', end = '')
for  item in shoplist:
    print(item, end = ' ')

print('\nI also have to buy rice.')
shoplist.append('rice')
print('My shopping list is now ', shoplist)

print('I will sort my list now')
shoplist.sort()
print('Sorted shopping list is ', shoplist)

print('The first item I will buy is ', shoplist[0])
olditem = shoplist[0]
del shoplist[0]
print('I bought the ', olditem)
print('My shopping list is now ', shoplist)

zoo = ('python', 'elephant', 'penguin')
print('Number of animals in the zoo is ', len(zoo))

new_zoo = 'monkey', 'camel', zoo
print('Number of cages in the new zoo is ', len(new_zoo))
print('All animals in new zoo are ',new_zoo)
print('Animals brought from old zoo are', new_zoo[2])
print('Last animal brought from old zoo is ', new_zoo[2][2])
print('Number of animals in the new zoo is ', len(new_zoo) - 1 + len(new_zoo[2]))

ab = {  'Swaroop'    : 'Swaroop@Swaroopch.com',
        'Larry'        : 'larry@wall.org',
        'Matsumoto'    : 'matz@ruby-lang.org',
        'Spammer'    : 'spammer@hotmail.com'
}

print("Swaroop's address is ", ab['Swaroop'])

del ab['Spammer']

print('\nThere are {0} contacts in the address-book\n'.format(len(ab)))

for name, address in ab.items():
    print('Contatc {0} at {1}'.format(name, address))

ab['Guido'] = 'guido@python.org'

if 'Guido' in ab:
    print("\nGuido's address is ", ab['Guido'])

name = 'Swaroop'

print('Item 0 is ', shoplist[0])
print('Item 1 is ', shoplist[1])
print('Item 2 is ', shoplist[2])
print('Item 3 is ', shoplist[3])
print('Item -1 is ', shoplist[-1])
print('Item -2 is ', shoplist[-2])
print('Character 0 is ', name[0])

print('Item 1 to 3 is ',shoplist[1:3])
print('Item 2 to end is ',shoplist[2:])
print('Item 1 to -1 is ',shoplist[1:-1])
print('Item start to end is ',shoplist[:])

print('Character 1 to 3 is ', name[1:3])
print('Character 2 to end is ', name[2:])
print('Character 1 to -1 is ', name[1:-1])
print('Character start to end is ', name[:])

bri = set(['brazil', 'russia', 'India', 'China'])
print('India' in bri)

PYTHON常见数据类型示例的更多相关文章

  1. python常见数据类型

    字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串烦人过程其实很简单,只需为变量分配一个值即可.例如: var = 'Hello Wor ...

  2. Python常见数据类型及操作

    基础数据类型 什么是数据类型? 我们人类可以很容易的分清数字与字符的区别,但计算机并不能,计算机虽然很强大,但从某种角度上看又很傻,除非你明确的告诉它,1是数字,“汉”是文字,否则它是分不清1和‘汉’ ...

  3. python常见数据类型及操作方法

    title: "python数据类型及其常用方法" date: 2020-04-21T10:15:44+08:00 可变数据类型:允许变量的值发生变化,即如果对变量进行append ...

  4. Python变量与常见数据类型

    Python变量 变量与常量:有时被通称为变量 变量:通常指代能够产生变化的量,多用以描述事物的变化状态 常量:通常指代稳定不产生变化的量,多用于描述事物的固定状态 # 代码层面的使用 myname ...

  5. Python 常见文件操作的函数示例(转)

    转自:http://www.cnblogs.com/txw1958/archive/2012/03/08/2385540.html # -*-coding:utf8 -*- ''''' Python常 ...

  6. Python常见文件操作的函数示例

    # -*-coding:utf8 -*- ''''' Python常见文件操作示例 os.path 模块中的路径名访问函数 分隔 basename() 去掉目录路径, 返回文件名 dirname() ...

  7. Python基本数据类型--列表、元组、字典、集合

    一.Python基本数据类型--列表(List) 1.定义:[ ]内以逗号分隔,按照索引,存放各种数据类型,每个位置代表一个元素. 2.列表的创建: # 方式一 list1 = ['name','ag ...

  8. [python学习手册-笔记]002.python核心数据类型

    python核心数据类型 ❝ 本系列文章是我个人学习<python学习手册(第五版)>的学习笔记,其中大部分内容为该书的总结和个人理解,小部分内容为相关知识点的扩展. 非商业用途转载请注明 ...

  9. Python基础:八、python基本数据类型

    一.什么是数据类型? 我们人类可以很容易的分清数字与字符的区别,但是计算机并不能,计算机虽然很强大,但从某种角度上来看又很傻,除非你明确告诉它,"1"是数字,"壹&quo ...

随机推荐

  1. sql快速生成大量数据

    先插入一条数据 insert into table(a,b,c,d) values(1,2,3,4) 然后重复执行以下sql语句 没执行一次 数据就会倍增 insert into table(a,b, ...

  2. AWS IAM (Identity and Access Management) 使用笔记

    为 AWS 管理控制台登录页面 URL 创建别名 $ aws iam create-account-alias --account-alias <value> 创建用户 $ aws iam ...

  3. magento flat和eav表连接的不同

    对于flat表,也就是普通的表,例如订单之类的sales_flat_order,这类型的连接,Collection连接 $table = Mage::getSingleton('core/resour ...

  4. jquery 可拖动进度条

    实现这个效果怎么弄呢? <!DOCTYPE html> <html> <head lang="en"> <meta charset=&qu ...

  5. .NET程序编译原理

    导语: CPU只认识二进制代码,那么C#源代码是怎样变成CPU可识别的二进制代码的呢? 步骤如下: 1.C#源码 2.运用VS自带的命令提示窗口,使用csc命令将C#源码转成程序集(EXE文件或DLL ...

  6. unity3d最新面试题与参考答案汇总

    1.在类的构造函数前加上static会报什么错?为什么? 构造函数格式为 public+类名,如果加上static会报错(静态构造函数不能有访问修饰符)原因:静态构造函数不允许访问修饰符,也不接受任何 ...

  7. 某些手机一直连不上adb的解决办法

    首先看驱动,就是用各种手机助手连接,看是否能识别,如果能够成功进入连接模式,说明可用,注意勾选一直使用该台计算机进行调试,如果这一步不勾选在后面也是没有办法的. 第二个就是看端口占用的问题,adb n ...

  8. 用正则表达式解析XML

    import java.util.regex.*; import java.util.*; /** * * <p>Title: Document</p> * * <p&g ...

  9. cognos 10.2.2 搭建网关做负载均衡

    最近要设计cognos服务器灾备模式,所以想到了cognos10自带的gateway负载均衡模式,搭建起来还是挺简洁的 设计背景: cognos主服务器:231 cognos灾备服务器:238 gat ...

  10. ios隐藏导航栏底线条和导航、状态栏浙变色

    方法一遍历法: 在你需要隐藏的地方调用如下代码 [self findlineviw:self.navigationBar].hidden = YES; -(UIImageView*)findlinev ...