《Python 第一章》基础知识
来源:互联网 发布:淘宝零食批发市场 编辑:程序博客网 时间:2024/06/05 05:15
第一章 基础知识1.1 简单使用和认识 python >>> 2**3 >>> pow(2, 3) >>> 2+8 >>> x = input("x: ") >>> print 'hello world' >>> print "hello world" >>> print 3 >>> print '3' >>> 0xAF 175 >>> 010 8 >>> abs(-10) >>> round(1.0/2.0) // 把浮点数四舍五入为最简介的整数值 1.0 * 模块 >>> import math >>> math.floor(32.9) 32.0 >>> math.sqrt(9) 3.0 >>>hello.py $ python2 hello.py
name = raw_input("What is your name?")print "Hello, " + name + "!"hello2.py $ chmod u+x hello2.py
#!/usr/bin/python2.7# you should zhushiname = raw_input("What your name ? \n")print "Hello " + name + " !\n"单引号 和 双引号
>>> "Let's go""Let's go">>> '"hello world" she said''"hello world" she said'字符串 (3种方法可以转化之) str, repr, 反引号。 print 与 不用 print
>>> '"hello world" she said''"hello world" she said'>>> "hello world"'hello world'>>> 10000L10000L>>> print "hello world"hello world>>> print 10000L10000>>> print repr("Hello, world")'Hello, world'>>> print repr(10000L)10000L>>> print str("Hello world")Hello world>>> print str(10000L)10000>>>input 与 raw_input 的区别
>>> raw_input("shuru : ")shuru : 6'6'>>> input("shuru : ") #默认为合法的python表达式shuru : 55>>>
长字符串, 原始字符串 和 Unicode
>>> print '''asddddddjkhasdjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkaweuwqbxcs'''asddddddjkhasdjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkaweuwqbxcs>>> print """asddddddjkhasdjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkaweuwqbxcs"""asddddddjkhasdjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkaweuwqbxcs>>> print 'C:\nowhere'C:owhere>>> print r'C:\nowhere'C:\nowhere>>> print r'C:\nowhere''\\' # 解决最后一个字符是 '\' 的情况! 完美解决C:\nowhere\>>> print u'hello, world' # Unicode 字符串, 在python3.0中,所有的字符串都是 Unicode 字符串hello, world>>>本章小结
*1 算法
*2 表达式
*3 变量
*4 语句
*5 函数
*6 模块 #例如 : math模块提供了很多数学函数
*7 程序
*8 字符串
本章涉及的新函数 : abs, cmath.sqrt, float(object) 将字符串和数字转换为浮点数, 同 int(Object), long(object), help(), math.ceil(number), pow(x, y[,z]), round, str(object)......
- 《Python 第一章》基础知识
- Python 第一章 基础知识
- 【python 基础教程】第一章 基础知识
- Python第一章基础知识
- 《python基础教程》第一章 基础知识
- Python第一章-基础知识
- Python 第一章 基础知识
- 第一章 Python基础知识概览
- Python学习笔记-第一章 基础知识
- Python 第一章 基础知识(1) 安装Python
- Python 第一章 基础知识(6) 函数
- Python 第一章 基础知识(7) 模块
- Python 第一章 基础知识(9) 字符串
- python基础教程学习笔记 第一章 基础知识
- Python基础教程学习笔记第一章:基础知识
- 第一章 基础知识
- 第一章 基础知识
- 第一章 基础知识
- 旋转字符串(循环移位,rotate)
- 数据库:dbms_lob用法小结
- C# 串口通讯日记
- 存储过程编写经验和优化措施
- Javascript Module Loader实现原理
- 《Python 第一章》基础知识
- VC获取并修改计算机屏幕分辨率(MFC)
- hdu2066一个人的旅行
- shell中的括号(小括号,大括号/花括号)
- tomcat原理解决
- java加密之我见
- C 语言变量的声明和定义
- C语言入门-struct&union&enum&typedef
- 事件和委托