haibaraxx的个人博客分享 http://blog.sciencenet.cn/u/haibaraxx

博文

按标题搜索
Python: 赋值
2017-5-31 21:27
多重赋值: 1) PI = pi = 3.1415926 PI 3.1415926 pi 3.1415926 2) PI = 3.1415926 pi = PI = PI * 2 pi 6.2831852 多元赋值: 1) x = 1 y = 2 ...
个人分类: Python|2054 次阅读|没有评论
Python3: for loop
2017-5-31 21:22
脚本: 注释纠正:range(1,10,2) returns the intergers 1 to 9 with the step of 2. 输出结果:
个人分类: Python|1905 次阅读|没有评论
Python3: while loop
2017-5-31 21:09
while (): else: # else部分可省略 脚本: 输出结果: while True - 使程序进入死循环。常与 break语句 连用,用以结束循环。 try-except语句见博文: Python: 异常处理try-except语句和with语句 http://blog.sciencenet.cn/blog-3031432-1059523.html
个人分类: Python|2039 次阅读|没有评论
python 神器
2017-5-31 18:00
1. Jupyter Notebook 2. Anaconda
个人分类: Python|1556 次阅读|没有评论
Python3: if statement
2017-5-31 16:38
if (): elif (): # elif部分可省略 else: # else部分可省略 脚本示例: 注: 1. 函数头 if/elif/else 以冒号:结尾 2. 函数体 print 前需要缩进(4个空格),否则会报错:IndentationError: expected an indented block (代码缩进). 输出结果: a is greater than b str1 i ...
个人分类: Python|2207 次阅读|没有评论
Python3: 格式化输出 print()
2017-5-31 04:40
参考: http://blog.csdn.net/lcore/article/details/9057967 print (...) print (value, ..., sep= ' ' , end= 'n' , file=sys.stdout, flush= False ) # n表示换行 name1 = 'Jane' name2 = 'Liz' ...
个人分类: Python|18401 次阅读|没有评论
Python3: 提示输入——input函数
2017-5-31 03:42
input () ——提示输入,输入对象为string格式,返回值为string格式。 python脚本示例如下: #!/usr/bin/python3 (注:#!后面的路径可通过在terminal中输入which python确定) myname = input ('What is your name?') print ('Hello ' + myname) print (myname + ', Let &# ...
个人分类: Python|16713 次阅读|没有评论
Python3:字符串 str(), repr(), eval()
2017-5-31 02:51
repr () ——返回对象的string格式,以供交互式解释器(也就是matlab中的command window)读取。 repr (3) '3' repr (3+4) '7' repr ( ' Hi ' ) 'Hi' print ('Hi'+repr(3)) Hi3 str() ——返回对象的strin ...
个人分类: Python|5819 次阅读|没有评论
Python 2: object.method(arguments)
2016-11-18 19:32
# object . method(arguments) age= age .append (30) age height= age .extend (height) age apples= apples .co u nt ('apples') # count how many times apples appears. 3 ...
个人分类: Python|1940 次阅读|没有评论
Python 2: concatenate arrays
2016-11-18 17:12
a= b= c=a + b print c a * 3
个人分类: Python|1617 次阅读|没有评论

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-18 15:40

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部