随笔 - 20  文章 - 0 评论 - 0 阅读 - 17386
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

#数据结构

##1.字符串
###首字母大写方法 name="adb test" print(name.title())
###全部大写 print(name.upper())
###全部小写 print(name.lower())
###字符串合并 first="adb" sencond="test" print(first+" "+second)
###制表符和换行符,在字符串中添加\n\t就可以
print("\n\tpython")
print("\n\t"+name)
###字符串删除空白(包括\t,\n,空格),使用lstrip,rstrip,strip函数
lstrip 删除字符串左侧空白
rstrip 删除字符串右侧空白
strip 删除字符串左右两边的空白

str1=" python"
str2="python "
str3=" python "
printf(str1.lstrip())
printf(str2.rstrip())
printf(str.strip())

##2.基本数据类型
##List []
array = ['aaa','bbb','ccc']
###添加插入元素
array.append("Item") 通过append追加元素
array.insert(0,"Item") insert插入元素
###删除元素
del array[0] del删除元素
array.remove['aaa'] 删除指定的元素
numitem = array.pop() 弹出最后一个元素并返回
###元素排序
cars = ["bmw","audi","toyota","subaru"]
cars.sort() 排序,修改了cars的顺序
print (cars)
cars.sort(reverse=True) 倒序
print (cars)
sorted(cars) 临时排序, sorted方法返回一个临时排序的list.
sorted(cars,reverse=True) 倒序
>>> print(sorted(cars,reverse=True))
['toyota', 'subaru', 'bmw', 'audi']
###反转列表
cars.reverse()
>>> print cars
['subaru', 'toyota', 'audi', 'bmw']
###列表长度
len(cars)
4
###遍历列表
>>> for item in cars:
... print(item)
subaru
toyota
audi
bmw

###数值列表
range是左开右闭的原则

>>> for i in range(1,5):
... print i
1
2
3
4

range返回的就是一个list,因此可以用来构造list.
>>> print range(1,6)
[1, 2, 3, 4, 5]

range的第三个参数表示步长.
>>> numbers = list(range(0,11,2))
>>> print numbers
[0, 2, 4, 6, 8, 10]

min,max, sum统计数据
>>> print numbers
[0, 3, 6, 9]
>>> print min(numbers)
0
>>> print max(numbers)
9
>>> print sum(numbers)
18

###列表解析
>>> squares = [ value**2 for value in range(1,11)]  
>>> print squares  
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100] 

 

posted @ 2019-10-28 10:42 步天有术 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 引 :https://www.jb51.net/article/37565.htm 问题:在下面的 template declarations(模板声明)中 class 和 typename 有什么不同? 代码如下: template<class T> class Widget; // uses " 阅读全文
posted @ 2019-03-25 14:59 步天有术 阅读(808) 评论(0) 推荐(0) 编辑
摘要: http://www.jb51.net/article/44271.htm // VerticalPointFromCircletoLine.cpp : Defines the entry point for the console application.// #include "stdafx.h 阅读全文
posted @ 2016-06-16 01:16 步天有术 阅读(401) 评论(0) 推荐(0) 编辑
摘要: // 内存对齐.cpp : Defines the entry point for the console application.// #include "stdafx.h"#include <iostream>using namespace std; #pragma pack(8) //指定对齐 阅读全文
posted @ 2016-03-30 15:22 步天有术 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 互斥量和信号量的区别 1. 互斥量用于线程的互斥,信号量用于线程的同步。 这是互斥量和信号量的根本区别,也就是互斥和同步之间的区别。 互斥:是指某一资源同时只允许一个访问者对其进行访问,具有唯一性和排它性。但互斥无法限制访问者对资源的访问顺序,即访问是无序的。 同步:是指在互斥的基础上(大多数情况) 阅读全文
posted @ 2016-03-30 09:55 步天有术 阅读(1001) 评论(0) 推荐(0) 编辑
摘要: [转载]关闭虚拟机(VMware)主板报警声-出错bell嘀嘀声音原文地址:关闭虚拟机(VMware)主板报警声-出错bell嘀嘀声音作者:gust90安装了虚拟机VMware后,不管是windows xp、windows 2003还是linux系统,都会有烦人的嘀嘀声响,特别是linux系统,即使... 阅读全文
posted @ 2015-06-16 14:38 步天有术 阅读(1357) 评论(0) 推荐(0) 编辑
只有注册用户登录后才能阅读该文。 阅读全文
posted @ 2015-02-15 10:41 步天有术 阅读(4) 评论(0) 推荐(0) 编辑
摘要: yum 安装软件时提示warning ,导致安装失败。如下图:据网上资料说这是由于yum安装了旧版本的GPG keys造成的。解决办法就是rpm --import /etc/pki/rpm-gpg/RPM* 阅读全文
posted @ 2014-10-09 21:32 步天有术 阅读(157) 评论(0) 推荐(0) 编辑
摘要: char *path = getenv("HOME");printf("path = %s\n",path);getenv是标准库函数,包含stdlib.h头文件就可. 阅读全文
posted @ 2014-07-21 17:03 步天有术 阅读(964) 评论(0) 推荐(0) 编辑
摘要: linuxC之access函数access():判断是否具有存取文件的权限相关函数stat,open,chmod,chown,setuid,setgid表头文件#include定义函数int access(const char * pathname, int mode);函数说明access()会检... 阅读全文
posted @ 2014-07-21 17:02 步天有术 阅读(1512) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示