学习Python第一天,命令很多跟Linux还有脚本语言相似。
学习Python第二天,看了一天,有点头疼,准备先休息一会,再继续。有一点C语言和Java基础,学起来不是很费劲。学习热情尚好。
学习了dir,math模块,import加载模块,有跟Linux相似的地方。
>>> dir(math)
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']
>>> help(math.pow)
Help on built-in function pow in module math:
pow(x, y, /)
Return x**y (x to the power of y).
模块的加载方式:
>>> from __future__ import division
>>> 5/2
2.5
>>> import math
>>> help(math)
Help on built-in module math:
NAME
math
Python 3 中字符串的连接,3舍弃了``,反向单引号,因为辨识度差。print后面需要加括号().
>>> a=("free")
>>> b=1988
>>> print a+'b'
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(a+'b')?
>>> print a
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(a)?
>>> print (a+b)
Traceback (most recent call last):
File "<pyshell#62>", line 1, in <module>
print (a+b)
TypeError: can only concatenate str (not "int") to str
>>> print (a+'b')
freeb
>>> print (a+`b`)
SyntaxError: invalid syntax
>>> print (a+str'b')
SyntaxError: invalid syntax
>>> print (a+str(b))
free1988
>>>
转义符
"\"
赋值时,“r"表示为原始字符串。字符串里面的内容没有含义
>>> d="c:\news"
>>> print (d)
c:
ews
>>> d=r"c:\news"
>>> print(d)
c:\news
>>> e="c:\\news"
>>> print e
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(e)?
>>> print (e)
c:\news
>>>
input函数,input()
>>> input("input your name:")
input your name:python
'python'
>>>
input结合print的小程序
print("Hello,World!")
name=input("What's your name?")
age=input("How old are you?")
print("Your name is " + name)
print("And you are "+age+" years old.")
ten=int(age)+10
print("After ten years,you will be "+ str(ten) +" years old. ")
运行结果。
D:\WPy64-3720\ZZ>python 0515-2.py
Hello,World!
What's your name?Zoe
How old are you?31
Your name is Zoe
And you are 31 years old.
After ten years,you will be 41 years old.
索引和切片
>>> lang=("study")
>>>
>>> lang[0]
's'
>>> lang.index("d")
3
>>> a=lang[2:4]
>>> a
'ud'
>>> b=[2:]
SyntaxError: invalid syntax
>>> b=lang[2:]
>>> b
'udy'
>>>
序列的切片,一定要左边的数字小于右边的数字,lang[-1:-3]就没有遵守这个规则,返回的是一个空。
(前包括,后不包括)
如果第二个数字大于字符串的长度,得到的返回结果就自动到最大长度位置终止。
学习Python第一天,命令很多跟Linux还有脚本语言相似。的更多相关文章
- (Linux基础学习)第一章:科普和Linux系统安装
第一章:科普和Linux系统安装 第1节:操作系统介绍OS:Operating System,通用目的的软件程序硬件驱动进程管理内存管理网络管理安全管理文件管理OS分类:服务器OS:RHEL,Cent ...
- 学习Python第一天:找了4本专属小白的书籍(前期入门打基础)
我们提供一个初学者最好的Python书籍列表.Python是一个初级程序员可以学习编程的最友好语言之一.为了帮助您开始使用Python编程,我们分享此列表.泡一杯茶,选一本书阅读,开始使用Python ...
- Clear Linux 为脚本语言提供更高的性能
导读 Clear Linux的领先性能不仅限于C/C++应用程序,而且PHP,R和Python等脚本语言也有很大的提升速度.在一篇新的博客文章中,英特尔的一位开发人员概述了他们对Python的一些性能 ...
- 系统学习python第一天学习笔记
1.计算机认识 1.常见的操作系统 win xp win7 win10 window server(服务器) linux centos,图形化界面差 ubuntu , 个人开发(图形化比较好) red ...
- 学习Python第一天 ---Hello World
引言 人生苦短,请用 Python(3.+) 越来越多的情况下使用Python语言进行"代码粘合"和"数据分析"变得非常方便,而且Python 在"爬 ...
- mac学习Python第一天:安装、软件说明、运行python的三种方法
一.Python安装 从Python官网下载Python 3.x的安装程序,下载后双击运行并安装即可: Python有两个版本,一个是2.x版,一个是3.x版,这两个版本是不兼容的. MAC 系统一般 ...
- 【转】Awk 命令学习总结、AWk命令系列学习(linux shell)
前面的话 学习linux 的同人,都知道linux shell文本处理能力非常强大.有一组强大的文本处理工具:grep,sed,awk . 其中grep 经常用作查找匹配文本.sed用作文本编辑替换. ...
- 学习python第一天总纲
1).python基础语法:4周课程(结束阶段考试) 2).前端知识点:html.css.javascript(js).jQuery 3).Linux(系统).数据库(关系型&非关系型) 4) ...
- Awk 命令学习总结、AWk命令系列学习(linux shell)
AWK基本语法 下面没有提到awk命令怎么使用了,你可以通过 运行:awk –h 查询到所有命令及参数!下面把awk作为一门语言分节介绍. linux awk 内置变量使用介绍 awk语言中,怎么 ...
随机推荐
- AFHTTPSessionManager下载文件 及下载中 进度条处理,进度条处理需要特别注意,要加载NSRunLoop 中
1.下载文件 和进度条处理代码 - (void)timer:(NSTimer *)timer{ // 另一个View中 进度条progress属性赋值 _downloadView.progress = ...
- HDU 5230 ZCC loves hacking 大数字的整数划分
http://acm.hdu.edu.cn/showproblem.php?pid=5230 把题目简化后,就是求 1---n - 1这些数字中,将其进行整数划分,其中整数划分中不能有重复的数字,如果 ...
- Ionic之button标签ng-click无反应解决
在使用Ionic中,使用按钮的ng-click事件,竟然点击没有反应,刚开始以为自己写得方法有问题才会不起作用,自己在点击之后就console.log()一个东西,但是console也是无法反应的.& ...
- MongoDB内置文档查看和修改
MongoDB设计的时候,有时候会设计内置文档,方便某个对象的统一.在这里略写了查看内置文档和更新内置文档. 1.查看 表为:realtimelogin realName为:123 realpa ...
- 【CSS】纯css实现立体摆放图片效果
1. 元素的 width/height/padding/margin 的百分比基准 设置 一个元素 width/height/padding/margin 的百分比的时候,大家可知道基准是什么? 举 ...
- iOS Runloop 消息循环
介绍 Runloop是一种事件监听循环,可以理解成一个while死循环,监听到事件就起来,没有就休息. Runloop可以在不同模式下进行切换,iOS有五种模式,其中UIInitializationR ...
- 字符串、String等转换
(1) String 转换为字符串 例:String s = "abcde";char[] a = s.toCharArray(); (2) 字符串转换为Stringchar[] ...
- get和post请求及进程和线程及cookie和session的区别
get和post请求及进程和线程及cookie和session的区别 1.get和post请求的区别 get请求是指向服务器进行获取查询数据的请求,post请求指向服务器提交数据的请求. get请求如 ...
- OPENFIRE 启动流程
在java>org>jivesoftware>openfire>starter,该类中的main方法启动,有图为证: 在start中方法分别调用unpackArchives和f ...
- js生成txt文件
HTML CODE: <div class="modal-footer"> <a onfocus="this.blur();" id=&quo ...