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# 制作透明窗体
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 【手把手教你Elmah】如何在MVC.NET项目中在线查看【错误日志】
一. 在NuGet下载Elmah.MVC dll文件! 或者点击下载dll文件,并且引用客户端. 二.配置WebConfig <sectionGroup name="elmah& ...
- 自己调用NTDLL函数
一.概述 在DLL初始化的时候有时不能调用其它系统DLL的函数,以免导致问题,但有时候又必须要调用怎么办?一种办法就是自己直接调用NTDLL接口,这样肯定没有问题. 下面我写个自己调用Registry ...
- android网络请求之get方法
package com.jredu.helloworld.activity; import android.os.Bundle; import android.os.Handler; import a ...
- 【转】驱动中的类class和节点
原文出处:http://blog.chinaunix.net/uid-23036581-id-2230558.html 一个类是一个设备的高级视图, 它抽象出低级的实现细节. 驱动可以见到一个SCSI ...
- javaweb学习总结二十五(response对象的用法一)
一:Reponse对象的概念 当客户端发送http请求时,服务器端会对每一次请求,创建request对象和response对象. response对象包括三个部分:响应头.响应状态码以及响应体 二:r ...
- [转]WPF 获取程序启动路径
本文转自:http://hi.baidu.com/lilipangtou/item/f1b7488e3c92c4d05e0ec1ab 在Windows Form程序中,获取自身的启动目录是非常容易的, ...
- CF Two Substrings
Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- C#操作ini
/// <summary> /// 读写INI文件的类. /// </summary> public class INIHelper { // 读写INI文件相关. [DllI ...
- CSS3 照片墙
HTML <body> <h2>照片墙制作</h2> <div class="container"> <img class=& ...