python 快速入门
根据以下几个步骤来快速了解一下python,目标是可以利用python来处理一些简易的问题或者写一些工具。
1
|
print ( 'HELLO WORLD' ) |
a = 2
if a==2:
a = a+2##这里需要注意缩进,python中是使用缩进来区分层次的
print(a)
a = 1
while a<5:
print(a)
a +=1
for i in range(1, 5):##range返回一个序列的数
print(i)
shopList=['c','eee','qqqq'] shopList.append('hhhh')##添加一个元素
print (shopList) shopList.sort()##数组排序
print (shopList) del shopList[0]##删除一个元素
print shopList print(', '.join(a))##间隔符设为","号,输出数据
meta = (3333,2222,333)
print ('length :',len(meta))
age=19
name='peter'
print ('%s is %d years old'% (name,age))
a = {'peter': 'peter@tooo.com', 'anne': 'iamanne@3.com'}##定义字典
print(a['peter']) if 'peter' in a:
print('peter is in') for key, value in a.items():##打印键和值
print(key + ':' + value) del a['anne']##删除对应key的键和值
for i in a.items():
print(i)
animal = 'elephant' if animal.startswith('ele'):##字符串是否以ele开头
print('start witch ele') print('a' in animal)##字符串是否包括‘a’字符串
print(animal.find('ant'))##找到‘ant’第一次出现的位置,没有找到返回-1
def returnMax(a,b):
if a>b:
return a
return b print(returnMax(100,39))
class Person:##定义一个类
num = 0##a是一个类变量 def say(self, word):
print(self.name+' say:', word)
return self.name def __init__(self, name):##__init__方法相当于java中的constructor .
Person.num += 1
self.name = name##这里name是一个对象变量 def __dosth(self):##使用__开头的方法和变量表示是私有变量
print('i am private method') def sayName(self):
print('i am', self.name)
self.__dosth() p = Person('peter')
p.say('hello world')
p.sayName()
class Peter(Person):##继承自Person
def __init__(self, height):
Person.__init__(self, 'peter')
self.height = height def sayHeight(self):
print('i am %d feet tail' % self.height) peter = Peter(6)
peter.sayName()
peter.sayHeight()
f = open(r'f:\11.txt', 'r')##打开一个文件只读
w = open(r'f:\33.txt', 'w')##打开一个文件可写
for l in f:
if l.find('iampeter') > 0:
w.write(l)
python 快速入门的更多相关文章
- Python快速入门
Python快速入门 一.基础概要 命名:h.py Linux命令行运行:python h.py 注释.数字.字符串: 基本类型只有数字与字符串 #python注释是这样写的 ''' 当然也可以这样 ...
- python快速入门及进阶
python快速入门及进阶 by 小强
- Python快速入门PDF高清完整版免费下载|百度云盘
百度云盘:Python快速入门PDF高清完整版免费下载 提取码:w5y8 内容简介 这是一本Python快速入门书,基于Python 3.6编写.本书分为4部分,第一部分讲解Python的基础知识,对 ...
- Python快速入门之与C语言异同
代码较长,建议使用电脑阅读本文. 10分钟入门Python 本文中使用的是Python3如果你曾经学过C语言,阅读此文,相信你能迅速发现这两种语言的异同,达到快速入门的目的.下面将开始介绍它们的异同. ...
- 1、Python快速入门(0529)
学习来自马哥教育的视频,感谢马哥 编程语言: 用户: 问题空间 计算机:解决问题 解空间 抽象: 机器代码-->微码编程-->高级语言 (语言的高下级的是根据语言是否被人类容易理解或者更接 ...
- python快速入门——进入数据挖掘你该有的基础知识
这篇文章是用来总结python中重要的语法,通过这些了解你可以快速了解一段python代码的含义 Python 的基础语法来带你快速入门 Python 语言.如果你想对 Python 有全面的了解请关 ...
- Python与C语言基础对比(Python快速入门)
代码较长,建议使用电脑阅读本文. 10分钟入门Python 本文中使用的是Python3 如果你曾经学过C语言,阅读此文,相信你能迅速发现这两种语言的异同,达到快速入门的目的.下面将开始介绍它们的异同 ...
- 第02章 Python快速入门
007.快速入门,边学边用 008.变量类型 print(type(变量)) 查看变量的了类型 现在常用的变量的类型有整型.浮点型.字符型 009.List基础模块 类型转换:str(8 ...
- 「数据挖掘入门系列」Python快速入门
Python环境搭建 本次入门系列将使用Python作为开发语言.要使用Python语言,我们先来搭建Python开发平台.我们将基于Python 2.7版本.以及Python的开发发行版本Anaco ...
随机推荐
- C# 文本框 TextChanged 延时触发
public partial class DelayTextBox : TextBox { #region private globals private System.Timers.Timer De ...
- A problem is easy
描述When Teddy was a child , he was always thinking about some simple math problems ,such as “What it’ ...
- How to installation V145 Renault CAN Clip diagnostic software
Eobd2.fr has launched the new 2015 V145 Renault CAN Clip diagnostic tool (SP19-A and SP19-B). Here i ...
- Windows配置端口转发
windows命令行下用netsh实现端口转发 微软Windows的netsh是一个命令行脚本实用工具.使用netsh工具 ,可以查看或更改本地计算机或远程计算机的网络配置.不仅可以在本地计算机上运行 ...
- [Windows] 解决kmplayer播放rmvb文件音视不同步
1. 到該帖子 http://www.kmplayer.com/forums/showthread.php?t=8755 下載附件中的4個檔案放到KMP 根 目錄下(此文件已在附件中上传) 2.於KM ...
- shell配置环境变量
我们在使用Xshell开发机时往往会遇到一些问题,比如使用某些命令他会报command not found,,出现这种情况的原因是我们必须要配置一下环境变量,这样就可以在任何path中访问了. 这就需 ...
- 让TabelView视图中自定义的Toolbar固定(不随cell的移动而移动)
//在viewDidLoad方法中创建Toolbartoolbar = [[UIView alloc] initWithFrame:CGRectMake(, , , )]; toolbar.backg ...
- EntityFramework使用中的一些Bug
1. No Entity Framework provider found for the ADO.NET provider 解决方法:添加 EntityFramework.SqlServer.dl ...
- canvas-js贝塞尔曲线代码在线生成工具
详细内容请点击 canvas贝塞尔曲线代码在线生成工具 可以快速生成二次.三次贝塞尔曲线的源码生成器,方便经常使用到canvas画图的同学使用,可以直接预览效果随意画出自己想要的图像. 生成源码效果预 ...
- ORACLE 数据库概述以及Oracel数据库的安装、卸载、使用
一:Orcale简介 1.发展史 1978年,Orcale诞生 1982年,Orcale3推出了,它是第一个能够运行在大型机和小型机上的关系型数据库 1997年,Orcale公司推出了基于java语言 ...